【发布时间】:2015-11-16 02:44:17
【问题描述】:
大家好,附上我正在使用的简单代码:
#include <stdio.h>
void main()
{char choice;
do
{
printf("\nHello World");
printf("\nDo you wish to continue:\n");
choice = getchar();
}
while(choice=='y');
}
在执行时我得到以下输出:
Hello World
Do you wish to continue
y
Hello World
Do you wish to continue
--------------------End of Program--------------------
如你所见, getchar() 函数在第二次迭代中不起作用。 更重要的是,程序没有等我在第二次迭代中输入“选择”。
出了什么问题?
【问题讨论】:
-
补充其他人所说的,
c应该是int。
标签: c while-loop codeblocks dev-c++ getchar