我有这个代码
whitespaces 是一个 int 类型,所以我可以使用 getchar 函数
do
{
...code...
whitespaces=getchar();}
while ( whitespaces != (EOF) || whitespaces!='\n');
但是当我按下 CTRL+Z 时它并没有退出循环(我使用的是 Windows 7)
我做错了什么?
编辑:谢谢大家...!很有帮助
最佳答案
您必须在 while
条件中使用 &&
而不是 ||
。
关于使用 getchar() 无法让 EOF 退出 do while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10198124/