fastread homefastrread library fastread menu

C++ : Concatenate Two Strings

Tutorial by:Manisha Dubey      Date: 2016-06-18 05:07:03

❰ Previous Next ❱

You can concatenate two strings easily using standard library function strcat() but, this program concatenates two strings manually without using strcat() function.

Source Code to Concatenate Two Strings without using strcat()


#include <iostream>
using namespace std;
int main()
{
    char s1[100], s2[100];
    int i, j;
    cout << "Enter first string: ";
    cin >> s1;
    cout << "Enter second string: ";
    cin >> s2;
    for(i=0; s1[i]!='\0'; ++i);  /* i contains length of string s1. */
    for(j=0; s2[j]!='\0'; ++j, ++i)
    {
        s1[i]=s2[j];
    }
    s1[i]='\0';
    cout << "After concatenation: " << s1;
    return 0;
}

Output

Enter first string: lol
Enter second string: :)
After concatenation: lol:)

❰ Previous Next ❱


C++

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website