C program to copy a string into another string

Complete program to copy a string into another string

#include <stdio.h>
int main()
{
char str[100], copy_str[100];
char *pstr, *pcopy_str;
pstr = str;
pcopy_str = copy_str;
printf("\n Enter the string : ");
gets(str);
while(*pstr != '\0')
{

*pcopy_str = *pstr;
pstr++, pcopy_str++;
}
*pcopy_str = '\0';
printf("\n The copied text is : ");
while(*pcopy_str != '\0')
{
printf("%c", *pcopy_str);
pcopy_str++;
}
return 0;
}

Output

Enter the string : C Programming
The copied text is : C Programming

Leave a Comment