Programming Examples
C program to concatenate two strings without using library function
Write a program to concatenate two strings. (Do not use inbuilt string function).
Solution
#include<stdio.h>
int main()
{
char str1[50],str2[30];
int a,b;
printf("Enter String 1");
gets(str1);
printf("Enter String 2");
gets(str2);
for(a=0;str1[a]!='\0';a++);
for(b=0;str2[b]!='\0';b++)
{
str1[a]=str2[b];
a++;
}
str1[a]='\0';
printf("Result String : %s",str1);
return 0;
}
Output
Enter String 1infomax
Enter String 2academy
Result String : infomaxacademy