C++ Program to Concat Two Strings
Write C++ Program to Concat Two Strings
// CPP Program to Concat Two Strings #include <iostream> #include <string.h> using namespace std; int main() { char S1[] = "Code", S2[] = "Crucks"; char S3[20]; int i = 0,j = 0; /* strcat(S1,S2); // Using inbuilt function cout << "Concatination string is " << S1); */ // Doing manually while(S1[i] != '\0') { S3[j] = S1[i]; i++; j++; } i=0; while(S2[i] != '\0') { S3[j] = S2[i]; i++; j++; } S3[j] = '\0'; cout << "String S1 :--> " << S1; cout << "\nString S2 :--> " << S2; cout << "\n\nConcatenated String :--> " << S3; return 0; }
Output:
String S1 :--> Code
String S2 :--> Crucks
Concatenated String :--> CodeCrucks