In article <11**********************@g14g2000cwa.googlegroups .com>,
CeyloR <w.*****@gmail.com> wrote:
++ndigit[c-'0'];
where c is the current character beeing read from the input (as
integer).
Am I right that the [c-'0'] stands for the convertion of the character
to it's integer value?
Not -exactly- but close.
c-'0' is certain to convert the character representation of
a digit into the numeric value represented... '0' to 0, '9' to 9
and so on.
The C language standards say almost nothing about internal
representation of characters: one of the very few things they
do promise is that the representation of the 10 digits will be
sequential and ascending starting from 0. The language standards
don't specify whether that sequence starts from 48 or from
176 or from 432493, just that they are in sequence.
The language standards do NOT make this promise for any other
characters -- the value of 'E' could be 19 less than the value of
'D' and the '$' character does not have to exist at all, for
example: only the digits are pinned down at all.
Anyhow, the [] don't have anything to do with the numeric
conversion process. The [] is the syntax for array indexing. c-'0'
produces an integral value, and ndigit[thevalue] indexes to
that location relative to the beginning of the ndigit array,
and then the ++ operator increments the value stored at that
location.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest