C Program to Concatenate Two Strings Without strcat
This C program concatenates two string without using string handling function strcat()
.
C Source Code: String Concatenation Without strcat()
#include<stdio.h>
int main()
{
char str1[50], str2[50];
int i, len=0;
printf("Enter first string:\n");
gets(str1);
printf("Enter second string:\n");
gets(str2);
/* Calculating length of first string */
for(i=0;str1[i]!='\0';i++)
{
len++;
}
/* Concatenating second string to first string */
for(i=0;str2[i]!='\0';i++)
{
str1[len+i] = str2[i];
}
str1[len+i]='\0';
printf("Concatenated string is: %s", str1);
return 0;
}
Output
Enter first string: Ram ↲ Enter second String: Shyam ↲ Concatenated string is: RamShyam Note: ↲ represents ENTER key is pressed.