The first thing to note is that you need to get rid of the spurious spaces in your comparison literals.
at the moment, the comparison is against teh whole value "space zero space" rather than "zero".
Try:
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);
c = getchar();
Note that I have included block start and end around every statement, even when they aren't necessary. It is worth doing this, particularly when you are just starting, as you can easily be confused by indentation into thinking a loop goes further than it actually does:
while (c != EOF)
printf(".");
c = getchar();
Looks like it works, but
while (c != EOF)
{
printf(".");
c = getchar();
}
Actually does!