如何基于其他2制作一个字符串?

时间:2014-05-16 01:29:40

标签: c string

我试图根据其他两个来制作一个混合字符串,例如,string1 =" Good Morning"和string2 ="大家好",所以我的脚本会这样输出:" Good Hello Morning的家伙"。

我差不多完成了..我尝试了什么:

int main() {
char frase2[99];
 int i =0;
 char frase3[99];

 printf("Type a sentence: ");
  gets(frase1);
 printf("Type a sentence: ");
 gets(frase2);

  char * pch1;
 char * pch2;

 pch1 = strtok (frase1," ");
 pch2 = strtok (frase2," ");

 while (pch1) {
strcat(frase3,pch1); 
pch1 = strtok (NULL, " ");

strcat(frase3,pch2); 
pch2 = strtok (NULL, " ");
  }
   puts(frase3);
 }

输出:示例:frase1 ="早上好&#34 ;; frase2 ="嘿伙计们&#34 ;;输出:错误

0 个答案:

没有答案