c program to concatenate two strings without using library function

Programming Example

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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad