我想弄清楚如何在不使用字符串副本和字符串连接的情况下将两个* chars连接在一起。concat two * chars w/o字符串函数?
我有这个至今:
char *concat(char *pt1, char *pt2)
{
char* c;
c = malloc(strlen(a) + strlen(b));
return c;
}
如果我用的是字符串函数我只是做:
strcpy(str3, str1);
strcat(str3, str2);
任何提示?
为终止子添加1。 'c = malloc(strlen(pt1)+ strlen(pt2)+ 1);' – 2015-02-05 19:35:48
检查'malloc()'的返回值。然后从每个字符串复制,直到达到0终止符。 – 2015-02-05 19:39:53
再次!请解释一下为什么这个问题被降低了。有人不明白,请求帮助,并得到downvote? – Quest 2015-02-05 19:56:41