Saturday, January 29, 2011

Concatenation of two strings in c++

Here is a simple program to concatenate a string with an other to make a single string

******************* Start of Program ************************

// Concatenation of strings

#include"iostream.h"
#include"conio.h"
#include"stdio.h"

void main()
{
clrscr();
char str1[20],str2[20];
cout<<"Enter 1st string :: ";
gets(str1);
cout<<"Enter 2nd string :: ";
gets(str2);

int i=0;

while(str1[i]!='\0')
{
i++;
}

int j=0;

while(str2[j]!='\0')
{
str1[i]=str2[j];
j++;
i++;
}

str1[i]='\0';

cout<<"\n\nNow string 1 is :: "<
getch();
}


******************************* END *****************************