C Examples String Copy
# C Language Example - String Copy
[ C Language Example](#)
Copy a string from one variable to another.
## Example - Using strcpy()
#include#includeint main(){char src; char dest; memset(dest, '', sizeof(dest)); strcpy(src, "This is "); strcpy(dest, src); printf("Final destination string : %sn", dest); return(0); }
The output is:
Final destination string : This is
## Example - Not Using strcpy()
#includeint main(){char s1, s2, i; printf("String s1: "); scanf("%s",s1); for(i = 0; s1 != ''; ++i){s2 = s1; }s2 = ''; printf("String s2: %s", s2); return 0; }
The output is:
String s1: tutorial String s2: tutorial
[ C Language Example](#)
YouTip