
问题一:为什么 if 里和下面的 ++ndigit[c - '0']; 的数字要加上 ‘’
问题二:++ndigit[c - '0']; 的 [ ] 里为什么要这样写,还有别的写法吗
代码:
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 == '\t' || c == '\n')
++nwhite;
else
++nother;
}
printf("digit = ");
for (i = 0; i < 10;++i)
printf(" %d", ndigit[i]);
printf(",white = %d,other = %d.", nwhite, nother);
getchar();
return 0;
}

