Re: detecting ASCII/EBCDIC

Discussion in 'C Programming' started by Keith Thompson, Sep 3, 2008.

  1. Pilcrow <> writes:
    > Is there a way that a proram can detect whether it is operating in an
    > ASCII or an EBCDIC environment?


    As others have suggested, testing the numeric values of some
    characters will probably tell you.

    But note that there are several different variants of EBCDIC. As for
    ASCII, remember that it's only a 7-bit character set. There are
    numerous larger sets based on ASCII. There are the 8-bit ISO 8859-N
    sets, with N running from 1 to about 15 last I heard. There's
    Unicode. There's a Windows-specific 8-bit extension to ASCII. And
    there are national variants that replace some of the punctuation
    characters with accented letters, though these aren't used much
    anymore.

    If at all possible, it's better to write your code so it will work
    with *any* character set. For example, if you want to know whether a
    character is a lowercase letter, don't use (c >= 'a' && c <= 'z'), use
    isascii(unsigned char(c)).

    What problem are you really trying to solve?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 3, 2008
    #1
    1. Advertising

  2. Keith Thompson

    Guest

    On Sep 3, 3:47 am, Keith Thompson <> wrote:
    > Pilcrow <> writes:
    > > Is there a way that a proram can detect whether it is operating in an
    > > ASCII or an EBCDIC environment?

    >
    > As others have suggested, testing the numeric values of some
    > characters will probably tell you.
    >
    > But note that there are several different variants of EBCDIC. As for
    > ASCII, remember that it's only a 7-bit character set. There are
    > numerous larger sets based on ASCII. There are the 8-bit ISO 8859-N
    > sets, with N running from 1 to about 15 last I heard. There's
    > Unicode. There's a Windows-specific 8-bit extension to ASCII. And
    > there are national variants that replace some of the punctuation
    > characters with accented letters, though these aren't used much
    > anymore.
    >
    > If at all possible, it's better to write your code so it will work
    > with *any* character set. For example, if you want to know whether a
    > character is a lowercase letter, don't use (c >= 'a' && c <= 'z'), use
    > isascii(unsigned char(c)).


    That should be islower((unsigned char)c) of course.
    (it's not the unsigned char mistake that bugs me; it's the isascii()
    one :S)
    , Sep 3, 2008
    #2
    1. Advertising

  3. writes:
    > On Sep 3, 3:47 am, Keith Thompson <> wrote:

    [...]
    >> If at all possible, it's better to write your code so it will work
    >> with *any* character set. For example, if you want to know whether a
    >> character is a lowercase letter, don't use (c >= 'a' && c <= 'z'), use
    >> isascii(unsigned char(c)).

    >
    > That should be islower((unsigned char)c) of course.
    > (it's not the unsigned char mistake that bugs me; it's the isascii()
    > one :S)


    D'oh! You're right, of course (and both mistakes bug me equally).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 3, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sylvain

    EBCDIC ascii conversion?

    Sylvain, Jun 13, 2004, in forum: Java
    Replies:
    2
    Views:
    21,775
    Thomas Weidenfeller
    Jun 14, 2004
  2. Re: detecting ASCII/EBCDIC

    , Sep 2, 2008, in forum: C Programming
    Replies:
    3
    Views:
    379
  3. Antoninus Twink

    Re: detecting ASCII/EBCDIC

    Antoninus Twink, Sep 2, 2008, in forum: C Programming
    Replies:
    2
    Views:
    325
    Richard
    Sep 3, 2008
  4. Re: detecting ASCII/EBCDIC

    , Sep 3, 2008, in forum: C Programming
    Replies:
    4
    Views:
    372
  5. Jean-Marc Bourguet

    Re: detecting ASCII/EBCDIC

    Jean-Marc Bourguet, Sep 3, 2008, in forum: C Programming
    Replies:
    7
    Views:
    419
    osmium
    Sep 4, 2008
Loading...

Share This Page