well i have two char array . when i try to concatenate both string using strcat function. Then my string "a" length reduced from 9 to 6. i also lost my string "a" .string b changed too.See in the output. why this is happening ???
here is what i have done
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[]="roomies!!";
char b[]="hey kammo DJ ";
char *c;
c=new char[50];
cout<<"before:-\n";
cout<<"len of a is "<<strlen(a)<<'\n';
cout<<"len of b is "<<strlen(b)<<'\n';
cout<<"len of c is "<<strlen(c)<<'\n';
cout<<"string a is = "<<a<<'\n';
cout<<"string b is = "<<b<<'\n';
cout<<"string c is = "<<c<<'\n';
c=strcat(b,a);
cout<<"\nafter:-\n";
cout<<"len of a is "<<strlen(a)<<'\n';
cout<<"len of b is "<<strlen(b)<<'\n';
cout<<"len of c is "<<strlen(c)<<'\n';
cout<<"string a is = "<<a<<'\n';
cout<<"string b is = "<<b<<'\n';
cout<<"string c is = "<<c<<'\n';
return 0;
}
output:-
before:-
len of a is 9
len of b is 13
len of c is 3
string a is = roomies!!
string b is = hey kammo DJ
string c is = =
after:-
len of a is 6
len of b is 22
len of c is 22
string a is = mies!!
string b is = hey kammo DJ roomies!!
string c is = hey kammo DJ roomies!!