Re: Portability question

From: Emmanuel Delahaye (emdelYOURBRA_at_noos.fr)
Date: 03/28/04


Date: 28 Mar 2004 19:35:44 GMT

In 'comp.lang.c', john <john@nospam.uk> wrote:

> New to C and working through chapter 1 of K&R2. In the program in 1.6,
> they use
>
> if (c >= '0' && c <= '9')
> ++ndigit[c-'0'];
>
> to count the occurrences of each digit in the input and put the result in
> an int array. According to them, 'This only works if '0', '1', ..., '9'
> have consecutive increasing values. Fortunately, this is true for all
> character sets.'

It true for the digits. A conforming C-implementation must have a charset
where digits values are consecutive and increasing.

The code is portable, as far as the implementation is conforming to the C
standard.

-- 
-ed- emdelYOURBRA@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/


Relevant Pages

  • Re: Portability question
    ... > have consecutive increasing values. ... > appear with a character set that represents the digits in decreasing order ... the 10 decimal digits ...
    (comp.lang.c)
  • Re: Bizarritudes
    ... > the digits 0 to 9 are ... > BC, Canada ... Prev by Date: ...
    (sci.math)
  • Re: Bizarritudes
    ... In the first 100000 digits the number of occurrences of ... the digits 0 to 9 are ... nonrandom. ... Prev by Date: ...
    (sci.math)