In this program, you will accept two string from user and concatenate two strings using pointer
#include<stdio.h>
int main()
{
char str1[50], str2[50];
char * p1 = str1;
char * p2 = str2;
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
/* increment till the end of str1 */
while(*(++p1));
// Coping str2 to str1
while(*(p1++) = *(p2++));
printf("Concatenated two string are: %s", str1);
return 0;
}
Enter first string: Study Enter second string: Day Concatenated two string are: StudyDay
#include<stdio.h>
int main()
{
char a1[20],a2[20],c[30];
int i,j;
char *p1,*p2,*p3;
p3=c;
p1=a1;
p2=a2;
printf("enter first string:");
gets(p1);
printf("enter second string:");
gets(p2);
for(i=0;*(p1+i)!='\0';i++)
{
*(p3+i)=*(p1+i);
}
for(j=0;*(p2+j)!='\0';j++,i++)
{ *(p3+i)=*(p2+j); }
*(p3+i)='\0';
printf("after concating two string: %s",p3);
return 0;
}
enter first string:Study enter second string:Fame after concating two string: StudyFame