Strcpy :
strcpy (str1,str2) copies the string pointed to by str2 to the string pointed to by str1 and terminates str1 with a null. The str2 must be a pointer to a null terminated string.
Syntax :
#include<string.h>
char *strcpy( char *to, const char *from );
C – STRCPY EXAMPLE PROGRAM :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char str1[20]=”learnerMode”; char str2[15]=”.com” clrscr(); printf(“\nBefore : \n str1 : %s\nstr2:%s”,str1,str2); strcpy(str1,str2); printf(“\n After :\n str1 : %s\nstr2 :%s”,str1,str2); getch(); return 0; } |
Output :
Before :
str1 : cprogrammingexpert str2 : .com After str1 : .com str2 : .com |