|
void fun (char * in, char * out),
If you want to allocate space for out in fun, it is very dangerous, because you don't know when to release him.
It depends on what function your fun wants to achieve.
You can do this if you just want to add the most characters.
void fun (char * in, char * out)
{
int i = strlen (in);
int i1 = strlen (out);
char * szBuff = new char [i1 + 1];
strcpy (szBuff, out);
if (out) {delete out; out = NULL;}
out = new char [i + i1 + 1];
sprintf (out, "% s% s", szBuff, in);
delete [] szBuff;
}
void main ()
{
char * out = new char [6];
strcpy (out, "Hello");
fun ("LZ", out);
printf ("% s\n", out);
delete [] out;
} |
|