G
Gus Tabares
Hello all,
I'm having a bit of trouble understanding a snippet of code in the
K&R book I'm reading. Basically it's something like this:
int ndigit[10];
for (i = 0; i < 10; i++)
ndigit = 0;
int c;
while ((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
.... The problem is with the last line here. Why is it that the
substraction is needed here? Why couldn't it just be ++ndigit[c]? I
may be missing something totally here.
Thanks,
Gus
I'm having a bit of trouble understanding a snippet of code in the
K&R book I'm reading. Basically it's something like this:
int ndigit[10];
for (i = 0; i < 10; i++)
ndigit = 0;
int c;
while ((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
.... The problem is with the last line here. Why is it that the
substraction is needed here? Why couldn't it just be ++ndigit[c]? I
may be missing something totally here.
Thanks,
Gus