This function copies the contents of one string (source) to another string (destination).
Syntax:
strcpy(destination, source);
Explanation:
- source: A pointer to the source string.
- destination: A pointer to the destination string.
Note: To copy one string to another. Ensure that the destination has enough space to hold the source string.
Example:
#include <stdio.h>
#include <string.h>
int main() {
char source[] = "My World";
char destination[10];
strcpy(destination, source);
printf("destination string is : %s", destination); // Output: destination string is : My World
return 0;
}
Output:
destination string is : My World