String Functionsstrcat Consider the following code char stri
String Functions-strcat Consider the following code: char string1[25] -\"Total Eclipse \"; char string2[11] = \"of the Sun\"; cout
Solution
Code:
#include <iostream>
#include <cstring>
using namespace std;
void strcat( char* string1, char* string2 ){
int l1 = strlen(string1);
int l2 = strlen(string2);
for(int i = 0; i < l2; i++){
string1[l1+i] = string2[i];
}
string1[l1+l2] = \'\\0\';
}
int main(){
char string1[20] = \"Total Eclipse \";
char string2[11] = \"of the Sun\";
cout << string1 << endl;
cout << string2 << endl;
strcat( string1, string2 );
cout << string1 << endl;
}
1. Strings are concatenated
2. Seems to be running same. Note that, string1 has only 20 characters, concatenation results in size 20, still prints fine
![String Functions-strcat Consider the following code: char string1[25] -\ String Functions-strcat Consider the following code: char string1[25] -\](/WebImages/28/string-functionsstrcat-consider-the-following-code-char-stri-1077139-1761565120-0.webp)