In this program, you will take two String inputs from the user and concatenate two strings without using strcat() library function.
#include<stdio.h>
int main()
{
char s1[10],s2[10],c[20];
int i,j;
/* Input two string from user stored in s1 and s2 */
printf("\n enter first string:");
gets(s1);
printf("\n enter second string:");
gets(s2);
// copy s1 array string into c array
for(i=0;s1[i]!='\0';i++)
{
c[i]=s1[i];
}
// copy s2 array string into c array
for(j=0;s2[j]!='\0';j++,i++)
{
c[i]=s2[j];
}
/* add null character '\0' at the end because string always terminated by a null character '\0' */
c[i]='\0';
printf("\n after concating two string:%s",c);
return 0;
}
enter first string:gaurav enter second string:prajapati after concating two string:gaurav prajapati