Write a program to copy the one string into another string

//this is a program to copy the string
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[20],str2[20];
int i=0,length=0;

printf("\n\nEnter Content of string1: ");
scanf("%s",str1);

printf("\n\nBefore Copying the contents of Strings: \n\nString1=%s \n\nString2=%s\n\n",str1,str2);

//finding the lengh of the string
while(str1[i]!=NULL)
{
length++;
i++;
}

for(i=0;i<length;i++)
{
str2[i]=str1[i];
}
str2[i]=NULL;

printf("\n\nAfter Copying the Strings:\n\nString1=%s\n\nString2=%s",str1,str2);

getch();
}


Previous
Next Post »