STRCPY() Function – C Program

STRCPY() Function – C Program

Write a C Program to copy contains of one string to another string.

STRCPY() Function :- The STRCPY() function used to copy contains of one string to another string in c language.

The Syntax of STRCPY() Function :

strcpy (str1, str2) – It copies contains of str2 into str1.
strcpy(str2, str1) – It copies contains of str1 into str2.

Example of STRCPY() Function C Program

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

int main()
{
 
char str1[100], str2[100];
 
printf("Please enter the first string = ");
gets(str1);

printf("\nPlease enter the second string = ");
gets(str2);
 
strcpy(str1,str2);

printf("\nThe str1 after copy = %s", str1);

return 0;
}

The output of STRCPY Function C Program is :

Please enter the first string = 

Please enter the second string = MeeraAcademy

The str1 after copy = MeeraAcademy

 

Leave a Reply

Your email address will not be published. Required fields are marked *