C program to concatenate two strings

Complete program to concatenate two strings

#include <stdio.h>
#include <conio.h>
int main()
{
char str1[100], str2[100], copy_str[200];
char *pstr1, *pstr2, *pcopy_str;
clrscr();
pstr1 = str1;
pstr2 = str2;
pcopy_str = copy_str;
printf("\n Enter the first string : ");
gets(str1);
printf("\n Enter the second string : ");
gets(str2);
while(*pstr1 != '\0')
{
*pcopy_str = *pstr1;
pcopy_str++, pstr1++;
}
while(*pstr2 != '\0')
{
*pcopy_str = *pstr2;
pcopy_str++, pstr2++;
}
*pcopy_str = '\0';
printf("\n The concatenated text is : ");
while(*pcopy_str != '\0')
{
printf("%c", *pcopy_str);
pcopy_str++;
}
return 0;
}

Output

Enter the first string : Data Structures Using C by
Enter the second string : Reema Thareja
The concatenated text is : Data Structures Using C by Reema Thareja

Leave a Comment