我正在研究C编程书。我在数组部分(1.6)中有一个问题,说:“让我们编写一个程序来计算每个数字,空格字符(空白,制表符,换行符)和所有其他字符的出现次数。
#include <stdio.h>
/* count digits, white space, others */
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 == '\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);
}
这是编译代码。如果我输入23,请输入23,然后输入ctrl + d,它将返回“数字= 1044509184,空格= 2,其他= 0”。为什么?数字在做什么?