【发布时间】:2019-01-28 16:20:22
【问题描述】:
我正在尝试制作一个程序来计算输入的字符数,但 EOF 信号似乎有问题,因为在我按 Enter 后程序没有结束。我不想使用标志来手动终止它。
我尝试过使用 CTRL+Z 和 CTRL+X 、 CTRL+D 或输入 -1,但都没有奏效。
#include <stdio.h>
void main()
{
double count;
for(count=0; (getchar())!=EOF; ++count)
{
;
}
printf("Char Count%.0f\n",count);
}
我使用的是 Windows 10、Atom 编辑器、gpp-compiler (3.0.7) 包(由 kriscross07 提供)和 minGW 8.2.0。
【问题讨论】:
-
Windows 上的 ctrl-c
-
@ryyker ctrl-c 不发送中断信号?
-
@bruno - 程序完全按照编写的方式在 WINdows 上使用 ctrl-c 中断。
-
@ryyker 所以这不是 OP 想要的
-
除此之外,为什么要使用 double 而不是 int(或 unsigned int)来计数?
标签: c mingw atom-editor eof