I'm currently learning C from an analog copy of The C Programming language. While it has been helpful in understanding the fundamental aspects of programming, I'm having trouble in understanding how my programs copied directly from the examples in the textbook are not producing an output in the terminal, nor are they explicitly requesting an input. I figured there's a giant hole in my comprehension of what's going on.
Currently I'm on section 1.6 on arrays. Here's the example code:
#include <stdio.h>
int 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 == '
' || c == '')
++nwhite;
else
++nother;
printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d
", nwhite, nother);
}
In the text since it's C89, it didn't include the int
before main()
, which I added. It's not spitting out any errors, but it also isn't spitting out anything else after I compile it. What am I missing?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…