C program to copy a string using string function(strcpy)

C program to copy a string using string function(strcpy)

This C program is to copy a string using string function(strcpy).String function strcpy is used to copy a string.

Do not forget to include ‘string.h’ header file.

Program

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

void main()
{
    char str1[100],str2[50];

    printf("Enter string str1\n");
    gets(str1);
    
    strcpy(str2,str1);
    printf("Copied String(str2) is %s",str2);
}

Output

Share Me!