完整代码:
#include <stdio.h>
#include <string.h>
#include <malloc.h> #define TRUE 1
#define FALSE 0 char *
strca(char *, char *); char *
join1(char *, char *); int
main(void) {
char *a = "你好";
char *b = "de我";
printf("%s\n", strca(a, b));
} char *
strca(char *des, char *src) {
char *r = (char *)malloc(sizeof(strlen(des)) + sizeof(strlen(src)) + ); //尾部存放'\0'中终止符.
if(!r) {
printf("out of memory!\n");
return FALSE;
}
char *tmp = r; //保存首地址.
/* while( *r++ = *des++ )
*/ ; while( *des )
*r++ = *des++; while( *r++ = *src++ )
;
return tmp;
}
最近在打C基础,现在还没完全弄明白 strca 函数中,注释部分(第 29~30 行)的代码为什么不能达到想要的效果.这两天才开始研究 x86和c的disassembly,国内的资料少,再加上最近复习考研,有点忙,慢慢来吧.