我对 Linux Mint 还比较陌生,并且有点想重新开始编程。我正在尝试使用 Brian W. Kernighan 和 Dennis M. Ritchie 编写的 C 编程来学习阅读、复制和计数的概念。
我理解行计数、字数计数等概念,但每当我运行代码时,我都不会在终端窗口上得到输出,而当我在 codechef 上使用在线编译器时却得到输出。
有人可以解释为什么会发生这种情况以及解决方案吗?
谢谢。 :)
#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;
}
printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n",nwhite, nother);
}
最佳答案
你认为这有什么作用?
while ((c = getchar()) != EOF)
这里看起来你想执行代码直到 c == '\n'
关于c - 当我在 Linux Mint 的终端窗口上编译具有 getchar() 等的程序时,我没有得到输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33540311/