C program to copy the elements of one string to the another

Refer to the following pages to learn the basics before learning this example.

Loading…

This program will ask the user to enter a string in one of the variables and then copies the variable into another variable. The program will display the second variable to illustrate the activities perform within the program. The output of the second variable will be the same as that of the first variable as we have copied the element of the first string into the second.

Code:

#include
#include
int main(){
        char n1[100], n2[100];
        puts("Enter the string: ");
        gets(n1);
        strcpy(n2, n1);// copies the elements of the first string to the second
        puts(n2);// displays the elemnts of the second string 
}

The above code will display its output as below.

Output:

Enter the string:
Programming Techniques
Programming Techniques
Loading…