<分区>
K&R
字符计数示例 我无法获得书中预期的输出。例如,当我输入“我回来了”并按回车键时,它应该会给我一个答案,但为什么不会?
#include <stdio.h>
/* count characters in input; 1st version */
main() {
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
<分区>
K&R
字符计数示例 我无法获得书中预期的输出。例如,当我输入“我回来了”并按回车键时,它应该会给我一个答案,但为什么不会?
#include <stdio.h>
/* count characters in input; 1st version */
main() {
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
最佳答案
我认为您没有看到输出,因为您没有从键盘发送 EOF
。因此,尝试通过按 Ctrl + D
来发送它。
关于来自 K&R 的字符计数示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21663510/