strcpy () function in c program
C Program to Copy String Using strcpy() :
In the C Programming Language, the strcpy function copies the string pointed to by s2 into the object pointed to by s1. It returns a pointer to the destination.
Parameters or Arguments
program code :
#include<stdio.h>
#include<string.h>
int main()
{
char st[100];
printf("Ente the valu : ");
scanf("%s",&st);
char st2[100];
strcpy(st2,st);
printf("%s",st2);
}
Output :
sr3= atikur
C Program to Copy String with Using strcpy():
You can use the strcpy() function to copy the content of one string to another but, this program copies the content of one string to another manually without using
strcpy()function.
program code :
#include<stdio.h>
int main()
{
char st[100];
char st3[100];
int i,j;
printf("Enter the valu : ");
scanf("%s",&st);
for (i=0; st[i]!='\0'; i++)
{
st3[i]=st[i];
}
st3[i]!='0';
printf("%s",st3);
return 0;
}
output :
st3=atikur

No comments