Ad Code

Responsive Advertisement

strcpy() function in C ? With Example

Copy String: strcpy() in C


The strcpy(destination, source) function copies the source string in destination.

Example:
c
#include <stdio.h> 
#include <string.h> 
int main()
char source[] = "Hello, World!"
char destination[20]; // Make sure the destination array is large enough 
strcpy(destination, source); 
printf("Source: %s\n", source);
printf("Destination: %s\n", destination); 
return 0
}


In this example:
We have a source string, "Hello, World!", stored in an array called source.
We have a destination array, destination, which should be large enough to hold the contents of the source string.
The strcpy() function is then used to copy the contents of the source string to the destination.

After the strcpy() function is executed, the destination array will contain the same string as the source array.

Post a Comment

0 Comments