Write A program in C to copy one string into another String ?

/ ** Write A program in C to copy one string into another String **/

void stringCpy(char* s1,char* s2);

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

printf(“Enter string 1: “);
scanf(“%[^\n]s”,str1);//read string with spaces

stringCopy(str2,str1);

printf(“String 1: %s \nString 2: %s\n”,str1,str2);
return 0;
}

void stringCopy(char* s1,char* s2)
{
int j=0;
while(s2[j]!=’\0′)
{
s1[j]=s2[j];
j++;
}
s1[j]=’\0′;
}

Leave a Reply

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