我一直在阅读《C 编程语言》,并且了解了输入和输出的这一部分。
I've read other threads saying that the console doesn't recognize enter as EOF
. So that I should use CTRL + Z in Windows or CTRL + D in Unix (neither of those is working for me).
我还读到其他人问同样的问题,他们说他们可以让它工作,他们的代码中的问题是语法而不是程序没有终止。
还有其他解决方案吗?
这是代码:
#include <stdio.h>
main()
{
int nb, nl, nt, c;
nb = 0;
nl = 0;
nt = 0;
while ((c = getchar()) != '\n') {
if (c == ' ')
++nb;
else if (c == '\n')
++nl;
else if (c == '\t')
++nt;
}
printf("Input has %d blanks, %d tabs, and %d newlines\n", nb, nt, nl);
}
编辑:\n
本来应该是 EOF,我在发布之前搞乱了,我忘记了我更改了它:P
它不适用于EOF
两者都不是,我只是跳过了那个。
while ((c = getchar()) !=EOF) {
}
Then use Ctrl+Z or F6 on Windows
以下将等待\n
or EOF
,哪个先出现
while((c = getchar()) != '\n' && c != EOF){
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)