Now we will see a program in which we use the strcpy function to copy one string into another.
srtcpy(s1, s2) according to this statement the second string ‘s2’ will be copied to the first string ‘s1’.
Table of Contents
Program
#include<stdio.h> #include<string.h> int main() { char s1[20]; char s2[]="Hello world"; strcpy(s1,s2); printf("Source string =%s\n",s2); printf("copied string =%s\n",s1); return 0; }
Output
Explanation
‘s1’ is declared with some size because we want the string ‘s2’ to get copied in ‘s1’. The array size given to ‘s1’ must be equal to or greater than the size of the string ‘s2’.
0 Comments