1个回答
推荐于2018-04-30
展开全部
举个简单例子,不给完整代码了。
char* str1 = "I am No.1";
char* str2 = "I am No.2";
char* str3 = "I am No.3";
int totalLen = strlen(str1) + 1 + strlen(str2) + 1 + strlen(str1) + 1 ;
char* strAll = (char*) malloc(totalLen * sizeof(char));
strcpy(strAll, str1);
strcat(strAll, " ");
strcat(strAll, str2);
strcat(strAll, " ");
strcat(strAll, str3);
...
...
...
free(strAll);
char* str1 = "I am No.1";
char* str2 = "I am No.2";
char* str3 = "I am No.3";
int totalLen = strlen(str1) + 1 + strlen(str2) + 1 + strlen(str1) + 1 ;
char* strAll = (char*) malloc(totalLen * sizeof(char));
strcpy(strAll, str1);
strcat(strAll, " ");
strcat(strAll, str2);
strcat(strAll, " ");
strcat(strAll, str3);
...
...
...
free(strAll);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询