Hello all,
I am not new to programming on high level but very new to low level programming and having very tough time understand K&R book example at very begining.
Can someone please clarify why below has to be subtracting 0 from the digits in the array?
I tried just c as subscripts and does not work. It just prints 0..........
When I look at that array, I see no benefit by subtracting 0 from digit I find in file..(at least to my naked untrained eyes)
Please let me know.
thank you!!!
Code:main() { int c, i, nwhite, nother; int ndigit[10]; nwhite = nother = 0; for ( i = 0; i < 10; ++i ) ndigit[i] = 0; while ( ( c = getchar() ) != EOF ) if ( c >= '0' && c <= '9' ) /*** ++ndigit[c-'0']; ****/ ++ndigit[c]; else if ( c == ' ' || c == '\n' || c == '\t' ) ++nwhite; else ++nother; printf("digits ="); for ( i = 0; i < 10; ++i ) /* printf("%d =====> ",i); */ printf("%d\n", ndigit[i] ); printf(", white space = %d, other = %d\n", nwhite, nother); }



LinkBack URL
About LinkBacks



