Here you will get C++ program to concatenate two string without using library function.
Below program will read two strings from user and then concatenate them to form third string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<iostream> using namespace std; int main() { char str1[30],str2[30],str3[60]; int i,j; cout<<"Enter first string:"; gets(str1); cout<<"\nEnter second string:"; gets(str2); for(i=0;str1[i]!='\0';++i) str3[i]=str1[i]; for(j=0;str2[j]!='\0';++j) str3[i+j]=str2[j]; str3[i+j]='\0'; cout<<"\nThe concatenated string is "<<str3; return 0; } |
Output
Enter first string:Hello
Enter second string:World
The concatenated string is HelloWorld
easiest solution ……. thanks
really useful. Thank you so much!