只是一个简单的问题; 我一直在通过K&R和数字/空白/其他计数器的代码工作正常.然而,虽然我试图了解我的功能,但else我遇到了一些不能按预期工作的东西.
书中的代码如下:
#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; …Run Code Online (Sandbox Code Playgroud)