我的C阵列测试程序不工作

我的C阵列测试程序不工作,c,C,我正在读C编程语言第二版。我正在做教程介绍中的2.10。我必须写一个关于数组的程序。它应该计算数字、空格和其他数字。以下是节目: #include <stdio.h> #include <stdlib.h> int main(void) { int c, i, nwhite, nother; int ndigit[10]; nwhite = nother = 0; for (i = 0; i < 10; ++i) ndigit[i] = 0; while

我正在读C编程语言第二版。我正在做教程介绍中的2.10。我必须写一个关于数组的程序。它应该计算数字、空格和其他数字。以下是节目:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
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);
return 0;
}
#包括
#包括
内部主(空)
{
int c,i,nwhite,other;
int-ndigit[10];
nwhite=nother=0;
对于(i=0;i<10;++i)
ndigit[i]=0;
而((c=getchar())!=EOF)
如果(i=0;i<0;++i)的(c>='0'&&c
这是错误的。

这是:

printf("digits =");
for (i = 0; i < 0; ++i)
    printf(" %d ", ndigit[i]);
printf(“digits=”);
对于(i=0;i<0;++i)
printf(“%d”,ndigit[i]);

循环的头的
中有一个断开的中间部分;
i<0
将不会为真(永远!)因此循环将不会运行。

请说明正确的code@UddhavaSwaminathan不,我让它作为练习。它是我<10请看得更近些,或者请提到你看到错误的那一行。不,它是
iIt给出了与书中给出的类似的输出,但不是正确的1)
prog
2)
i<0
-->
i<10
编译所有警告和调试信息(例如
gcc-Wall-Wextra-g
如果使用…),然后使用调试器(例如
gdb
)。这是必须具备的基本技能。我在调试器或生成文件中没有错误。我正在使用Codeblocks@UddhavaSwaminathan:那么,请你去找你的故障调试器寻求帮助;很明显,你非常需要它。停止诅咒钉子,修理锤子!@Ruud他可能认为调试器是一个程序,它会给你一个问题列表我们的代码:-)它是i<10请看得更近些,或者请提到你看到错误的那一行请停止回答这个问题。谢谢你的帮助
i
是一个带符号的int,所以它最终会停止(除非循环的内容不会使它过早崩溃)。
printf("digits =");
for (i = 0; i < 0; ++i)
    printf(" %d ", ndigit[i]);