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.

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

int main() {

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

    printf("Enter string value:");
    scanf("%[^\n]%*c", str1); 

    strcpy(str2, str1);

    printf("First string value is:%s", str1);
    printf("\nSecond copy string value is:%s", str2);

    return 0;
}

Output:

Enter string value:Xiith.com
First string value is:Xiith.com
Second copy string value is:Xiith.com