回复 9楼 klyz505
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include <assert.h>
char *_StrCat(char *dest, char *src)
{
assert((dest != NULL) && (src != NULL));
dest = (char*)realloc(dest, strlen(dest)+strlen(src)+1);
strcat(dest, src);
return dest;
}
main()
{
char *str = (char*)malloc(1);
memset(str, 0, 1);
str = _StrCat(str, "话说天下大势,");
str = _StrCat(str, "分久必合,");
str = _StrCat(str, "合久必分。");
printf("%s\n", str);
free(str);
return 0;
}
[此贴子已经被作者于2016-7-16 21:25编辑过]