((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
c
gives you the current character. With the range checking you confirm it is a number by using its ASCII value
Check chr
column for 0
, it says 48
and for 8
it says 56
.So, '8'- '0'
gives 56 - 48
= 8
ndigit
is used to keep track of how many times a number occurs in with each element of the array representing the number of times its subscript has occured.
ndigit[0]
will ggive you number of times 0
has occurred and so on.. ndigit[x]
gives number of times x
appeared
[c - '0']
suppose your c
i.e current character is 8
then '8' - '0'
will give you 8
. so you get ndigit[8]
and you ++
that value [you initialised it to 0
at start]