C Program to copy string using strcpy function


In this program, You will learn how to copy string using strcpy function in c.


strcpy(str2, str1);


Example: How to copy string using strcpy function in c

Run it Now
#include<stdio.h>
#include<string.h>

int main() {

    char str1[100];
    char str2[100];

    printf("Enter String value :");
    fgets(str1, 100, stdin);

    strcpy(str2, str1);

    printf("\nThe First String value is :%s", str1);
    printf("\nThe Second Copy String value is :%s", str2);

    return 0;
}

Output:

Enter String value :Hello World
The First String value is :Hello World
The Second Copy String value is :Hello World