In this tutorial, we are going to share about the strcpy()
function in c programming language. By using the strcpy()
function, you can copy the one string to another string.
Here is the code syntax to use the strcpy()
function in the c programs.
1 | char *strcpy(char *str1, const char *str2) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <stdio.h> #include <string.h> int main () { char str1[20]; char str2[20]; strcpy(str1, "Apple"); printf("String str1: %s\n", str1); strcpy(str2, "Banana"); printf("String str2: %s\n", str2); strcpy(str1, str2); printf("String str1: %s\n", str1); return 0; } |
String str1: Apple
String str2: Banana
String str1: Banana
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.