To copy the one string into another using function
strcpy( ) : This function is used to copy the one string into another.The general form is ,void strcpy(target,source);
Consider the following program ,
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main( )
{
char str1[50],str2[50];
int i;
clrscr( );
printf("\nEnter the string :");
scanf("%s",str1);
strcpy(str2,str1);
printf("\nResult : %s",str2);
getch( );
}
output :
Enter the string : computer
Result : computer
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main( )
{
char str1[50],str2[50];
int i;
clrscr( );
printf("\nEnter the string :");
scanf("%s",str1);
strcpy(str2,str1);
printf("\nResult : %s",str2);
getch( );
}
output :
Enter the string : computer
Result : computer
Comments
Post a Comment