Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: detecting ASCII/EBCDIC

Reply
Thread Tools

Re: detecting ASCII/EBCDIC

 
 
Keith Thompson
Guest
Posts: n/a
 
      09-03-2008
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) kst- <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"
 
Reply With Quote
 
 
 
 
vippstar@gmail.com
Guest
Posts: n/a
 
      09-03-2008
On Sep 3, 3:47 am, Keith Thompson <ks...@mib.org> wrote:
> Pilcrow <pilc...@pp.info> 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)
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      09-03-2008
writes:
> On Sep 3, 3:47 am, Keith Thompson <ks...@mib.org> 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) kst- <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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting end of file for VHDL'93 Gary Thorpe VHDL 2 07-12-2005 07:42 AM
Detecting if Mozilla is Running Peter Firefox 1 04-30-2005 09:47 PM
Detecting edge in a clock synchronous porcess Praveen VHDL 2 04-12-2005 11:36 AM
Detecting of 'U' in a std_logic_vector Thomas Reinemann VHDL 4 11-03-2004 08:24 AM
detecting if program is running under X windows or not Paul Faulstich Perl 1 01-10-2004 07:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57