In C, you can do arithmetic on characters using your character codes. Thus, this ensures that you have a digit, it turns out which digit it is (by measuring its difference from zero), and then increases the score at the corresponding position in the array. When this is done, it ndigit[0]will contain the number of entries '0', ndigit[1]will contain the number of entries '1', etc.
source
share