这是我的 C 源代码。
当我在 Ubuntu 中构建它时,它开始获取字符,但我不知道如何结束程序,因为它不会以输入ENTER或回车结束。
EOF是什么意思?我怎样才能触发它?
这个来源也来自丹尼斯·里奇的一本书:
#include <stdio.h>
/* count digits, white space, others */
main ()
{
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar ()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c - '0'];
else if (c == ' ' || c == '\n' || c == '\t')
++nwhite;
else
++nother; …Run Code Online (Sandbox Code Playgroud)