Program to concatenate two strings without using strcat

2 years ago Admin 0

Concatenate two strings without using strcat

This article illustrates how to concatenate two strings without using strcat in c/c++.While loop is used to concatenate the two string.

concatenate two strings without using strcat

Here is the source code and output of both the programs.

C Programming language

Program


#include<stdio.h>
#include<conio.h>
void main()
{
char first[100],second[100];
int i=0,j=0;
clrscr();
printf("Enter first string:- ");
gets(first);
printf("Enter second string:- ");
gets(second);

while(first[i]!='\0')
{
 i++;
}
while(second[j]!='\0')
{
 first[i]=second[j];
 i++;
 j++;
}
printf("String after concatenation is :- %s",first);
getch();
}

After successfully compiling and executing the above C program,output is:-

concatenate two strings without using strcat


C++ Programming language

Program


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char first[100],second[100];
int i=0,j=0;
cout<<"Enter first string:- ";
gets(first);
cout<<"Enter second string:- ";
gets(second);
while(first[i]!='\0')
{
 i++;
}
while(second[j]!='\0')
{
 first[i]=second[j];
 i++;
 j++;
}
cout<<"String after concatenation is :- "<<first;
getch();
}

After successfully compiling and executing the above C++ program,output is:-

concatenate two strings without using strcat


Comment below if you are facing any problem or you find any error in the above program and also subscribe to our newsletter for more updates.


Read more c/c++ Programs published by snapcout:-

Program to copy one string into another using strcpy
Program to copy string without using strcpy()
Program to Convert String into Uppercase Using strupr()
Program to convert string into upper case without using strupr()
Program to convert string into lowercase using strlwr()


About article

Written By:- Admin

Published on:- 07/10/2017

Published By:- Snapcout


Don't forget to share the article if you like it:-