I have the following code snippet:
int ndigit[10] = {0,0,0,0,0,0,0,0,0,0};
void count() {
char c;
while (cin.get(c)) {
if (c>='0' && c<='9') {
ndigit[c-'0']++;
}
}
So c
has to be between 0 and 9 (with 0 and 9), so why it is necessary to index the array like ndigit[c-'0']
instead of just ndigit[c]
?
If I am right, in both cases a c
value can occur more then once, so a the value of ndigit[c-'0']
gets overwritten anyway...
I appreciate your wisdom!