A Function that Implements the strcmp() Function that Copies the Contents of one string to another

A Function that Implements the strcmp() Function that Copies the Contents of one string to another

·

1 min read

This program demonstrates the use of a custom function _strcpy() to copy a string from one array to another.

In the main() function, two character arrays str1 and str2 of size 20 are defined. str1 is initialized with the string "Hello".

The _strcpy() function is then called with arguments str2 and str1. This function takes two arguments: a destination string dest and a source string src. It copies the characters from the source string src to the destination string dest and returns a pointer to the destination string.

The ptr pointer in main() is assigned the return value of _strcpy() which is the address of the str2 array.

Finally, the program prints the contents of str1 and str2 using printf() function.

When this program is run, it will output the following:

str1: Hello
str2: Hello

This is because _strcpy() function copies the string "Hello" from str1 to str2, and the pointer ptr points to the beginning of str2 where the string "Hello" is copied.