strcpy() function in C is used to copy the contents from one string (source) to another string (destination).
The strcpy() function is defined in the header file string.h. It takes two arguments, destination and source. The source is from where the string is taken and the destination is to where the string is copied and written as follows:
strcpy(destination, source);
C Program for strcpy() function
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> #include <string.h> int main() { char str1[20] = "Simple2Code"; char str2[20]; printf("String on str2: %s.", strcpy(str2, str1)); return 0; } |
Output:
String on str2: Simple2Code.