我写了一个小程序来组合两个2d数组。下面是代码:连接两个2d char数组
#define MAX 7
int main(void) {
int i, j;
char *array1[] = {"Welt,", "bist", "du"};
char *array2[] = {"noch", "zu", "retten?"};
char final[MAX][MAX];
for(i = 0; i < 3; i++) {
// initialize ith names element with first name
strcpy(final[i], array1[i]);
}
for(j = 0; j < 3; j++) {
// concatenate the last name to the firstname+space string
strcat(final[i], array2[j]);
}
for (i = 0; i != 6; i++) {
printf("%s", final[i]);
}
return EXIT_SUCCESS;
}
我得到这样真的很奇怪输出:
世界报,bistbistdunochzuretten uretten恩???
而我想是这样的:
世界报,bistdunochzuretten
正如你可以看到它是不是完全错误的。词语之间不应有空格。
我该如何修复我的代码?
sry不,不起作用,或者我无法处理它。 – WirJun 2014-12-07 18:32:27
对不起,我没有说过,但现在尝试包括我在代码中的库。 – OiciTrap 2014-12-07 18:38:07
很高兴我能帮助你。 – OiciTrap 2014-12-07 18:50:06