I'm trying to find the number of occurrence of digit in input (typed number). I'm confused with subscript expression of array in the expression ++ndigit[ c - '0']
.
Here the code
#include <stdio.h>
/* count digits, white space, others*/
main() {
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for(i = 0; i < 10; ++i)
{ndigit[i] = 0;}
while ((c = getchar()) I= EOF)
{if (C >= '0' && C <= '9')
{++ndigit[c-'0'];}
/*here i stucked explain me how
subscript
expression going too work*/
elseif (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);
}