【发布时间】:2017-03-04 05:17:34
【问题描述】:
#include <stdio.h>
void main()
{
char couples[3][50] = { "Paul Kathy", "John Nora", "Martin Mary" };
char husbands[3][50];
char wives[3][50];
int i = 0;
int j = 0;
puts("Husbands: ");
for (i = 0; i < 3; i++)
{
while (couples[i][j] != ' ')
{
couples[i][j] = husbands[i][j];
j++;
}
husbands[i][j] = '\0';
puts(husbands[i]);
j = 0;
}
}
我之前创建了一个类似的程序,并且运行良好。然而,虽然这确实构建和编译成功,但它不能正确运行。本质上,我试图根据空格字符将情侣分成一个单独的字符串。我做错了什么?
【问题讨论】:
-
main有两个有效签名:int main (void)和int main (int, char **)。应该避免任何以其他方式教你的文学作品。寻求更好的学习材料,掌握 C 的基础知识并不难。 -
“运行不正确”?它有什么作用?
-
请参阅What should
main()return in C and C++,了解允许和不允许的全部细节。允许void main()的平台数量很少。
标签: c arrays string loops char