C String Function : strcpy()

The strcpy() function is used to copy the one string's content to another string. The syntax of strcpy() is :
char * strcpy ( char * destination, const char * source );
Where :
  • destination is the string where you want to copy.
  • source is the string which you want to copy on the destination.
Example :
strcpy(str1, str2);
The above statement copy str2's content to str1. Also note that the destination string length must be greater then or equal to the length of source string. And if it less then the source string then the entire source string value could not be copied into destination string.

Example C Program :
#include <stdio.h>
#include <string.h>

int main() {
  char str1[30];
  char str2[] = "Hello world, This is String.";

  strcpy(str1, str2);
  printf("%s\n", str1);
  return 0;
Output :

Hello world, This is String.

Note : We have to include the string.h header in our program to use the string function.

Links :