Home C Language Basic C Programs Syntax of strcpy() in C with Example

Syntax of strcpy() in C with Example

Syntax of strcpy()

strcpy(source_string,destination_string);

Write a program in C to copy one string to another string.

#include <stdio.h>

#include <string.h>

int main()

{

   char source[1000], destination[1000];

   printf(“Enter input  string\n”);

   fgets(source, sizeof source, stdin);

   strcpy(destination, source);

   printf(“Source string: %s\n”, source);

   printf(“Destination string: %s\n”, destination);

   return 0;

}

Output:

Enter input string:

Welcome to Ekvij.com

Source string: Welcome to Ekvij.com

Destination string: Welcome to Ekvij.com