C Program to Copy String

To copy string in C programming, you have to ask to the user to enter the string to make copy to another variable of same type using strcpy() function of string.h library.


#include <stdio.h>
#include <string.h>

     int main()
     {
         char source[1000], destination[1000];

         printf("Input a string\n");
         gets(source);

         strcpy(destination, source);

         printf("Source string: %s\n", source);
         printf("Destination string: %s\n", destination);

         return 0;
     }

Run:

 

No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...