strcpy(): String Copy in C Programming
String handling function strcpy()
is used to copy content of one string variable to another string variable i.e. strcpy(string2, string1)
copies content of string1 to string2.
strcpy() Syntax
strcpy ( string2, string1);
strcpy() Program
#include<stdio.h>
#include<string.h>
int main()
{
char str1[30], str2[30];
printf("Enter string:\n");
gets(str1);
strcpy(str2, str1);
printf("Coped string is: %s”, str2);
return 0;
}
strcpy() Program Output
Enter string: Welcome to C↲ Copied string is: Welcome to C Note: ↲ indicates ENTER is pressed.