[CODE]
1 #include <stdio.h>
2 main()
3
4 {
5 int c, i, nwhite, nother;
6 int ndigit[10];
7
8 nwhite = nother = 0;
9 for (i – 0; i < 10; ++i)
10 ndigit[i] = 0;
11
12 while ((c = getchar()) != EOF)
13 if (c >= ’0′ && c <= ’9′)
14 ++ ndigit[c - '0'];
15 else if (c == ‘ ‘|| c == ‘\n’|| c == ‘\t’)
16 ++ nwhite;
17 else
18 ++ nother;
19
20 printf(“digits =”);
21 for (i = 0; i < 10; ++i)
22 printf(” %d”, ndigit[i]);
23
24 printf(“, white space = %d, other = %d \n”,
nwhite, nother);
25
26
27 }
[/CODE]
运行之后提示“段错误”,这事怎末回事?谢谢。
>> 本文固定链接: http://www.vcgood.com/archives/3236
#include <stdio.h>
main()
{
int i, nwhite=0, nother=0,ndigit[10];
char c;
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);
}
谢谢,已经可以了。