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

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 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 Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz