strcpy in C: Copy Strings Easily
In C language, the strcpy function can be used to copy strings. Its prototype is:
char *strcpy(char *dest, const char *src);
dest is a pointer to the target string, while src is a pointer to the string to be copied. Here is an example code:
#include <stdio.h>
#include <string.h>
int main() {
char src[] = "Hello, World!";
char dest[50];
strcpy(dest, src);
printf("Source string: %s\n", src);
printf("Copied string: %s\n", dest);
return 0;
}
In the example above, a source string src and a destination string dest are first defined. Then the strcpy function is used to copy src into dest, followed by printing out the result.