CodePudding user response:
Char * stringcat (char * a1, char * a2)
{
Char * s3=new char [strlen (a1) + strlen (a2) + 1);
Char * temp=s3;
While (* a1! Temp++=='\ 0') {* * a1 + +; }
While (* a2! Temp++=='\ 0') * * a2 + +;
* temp++='\ 0';
Return the s3;
}
Int main (int arg c, char * argv [])
{
Char * t1="ABC";
Char * t2="123";
Char * tempstr;
Tempstr=stringcat (t1, t2);
Printf (" % s ", tempstr);
The delete [] tempstr;
getchar();
return 0;
}
CodePudding user response:
Remove the constCodePudding user response:
You have a problem of algorithm, this sentence: s3 [I + 1)='\ 0';CodePudding user response:
In local function declarations and new space, you should be in a local function release, suggested to:Char * s;
Char * stringCat (const char * s1, s2 const char *)
{
S=new char [strlen (a1) + strlen (a2) + 1);
.
}
Int main (int arg c, char * argv [])
{
.
The delete [] s.
}