Travel the source string, and copy the character one by one into targeted string. and add a null character at the end of the targeted string. We can also use strcpy() method to copy a string. for that, we must include string.h header file.
int main()
{
char str1[30],str2[30],i,fl=1;
printf("Enter A String: ");
gets(str1);
for(i=0;str1[i]!='\0';i++)
{
str2[i]=str1[i];
}
str2[i]='\0';
printf("\nCopied String : ");
puts(str2);
return 0;
}
#include<string.h> // for strcmp()
int main()
{
char str1[30],str2[30],i,fl=1;
printf("Enter A String: ");
gets(str1);
strcpy(str2,str1);
printf("\nCopied String : ");
puts(str2);
return 0;
}