Chinaunix
标题:
菜鸟求助阿
[打印本页]
作者:
a55569769
时间:
2011-04-23 21:49
标题:
菜鸟求助阿
1 #include <stdio.h>
2 main()
3 {
4 int c, i, nwhite, nother;
5 int ndigit[10];
6 nwhite = nother = 0;
7 for (i = 0; i < 10; ++i)
8 ndigit[i] = 0;
9 while ((c = getchar()) != EOF)
10 if (c >= '0' && c <= '9')
11 ++ndigit[c-'0'];
12 else if (c == ' ' || c == '\n' || c == '\t')
13 ++nwhite;
14 else
15 ++nother;
16 printf("digits =");
17 for (i = 0; i < 10; ++i)
18 printf(" %d",ndigit[i]);
19 printf(", white space = %d, other = %d\n",nwhite,nother);
20 }
第11行
++ndigit[c-'0']
是怎么回事,数组自加运算结果是啥阿
作者:
a55569769
时间:
2011-04-23 21:54
明白了,献丑献丑{:3_186:}
作者:
nketc
时间:
2011-04-23 22:22
回复
2#
a55569769
不是数组自加,是数组的那个元素。下标运算符[]的优先级比++高很多。
作者:
nketc
时间:
2011-04-23 22:22
权且数字名是个常量,不能对它做算术操作。
作者:
a55569769
时间:
2011-04-23 22:26
回复
3#
nketc
恩,直到拉,谢谢阿
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2