Write a Program to concatenate strings C++

A simple program to concatenate String c++ without using the library functions.

  • Input 2 strings.
  • Go to end of one string and add second after it.
  • put NULL ‘’ at the end of the string.

 Program to concatenate strings C++

#include<iostream>
using namespace std;

int main( )
{

    int l;
    char str1[80],str2[80];
    cout<<"Enter first string :";
    gets(str1);
    cout<<"Enter second string :";
    gets(str2);

    for(l=0;str1[l]!='';l++);

    for(int i=0;str2[i]!='';i++)
        str1[l++]=str2[i];

    str1[l]='';

    cout<<"nThe first string after adding second string content isnn"<<str1;

    return 0;
}

 

OUTPUT:

concatenate strings C++

Leave a Reply