Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » CGoto page 1, 2, 3, 4, 5  Next

detecting ASCII/EBCDIC

 
Jump to:  
 
Pilcrow
PostPosted: Tue Sep 02, 2008 8:11 pm    Post subject: detecting ASCII/EBCDIC
       
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?
 

 
Ben Pfaff
PostPosted: Tue Sep 02, 2008 8:24 pm    Post subject: Re: detecting ASCII/EBCDIC
       
Pilcrow <pilcrow@pp.info> writes:

Quote:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?

You could do something like this:

if ('A' == 0x41) {
/* Probably ASCII. */
} else if ('A' == 0xc1) {
/* Probably EBCDIC. */
}
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
 

 
Richard Heathfield
PostPosted: Tue Sep 02, 2008 8:29 pm    Post subject: Re: detecting ASCII/EBCDIC
       
Pilcrow said:

Quote:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?

Almost.

What you can do is check code points for the basic character set. If 'A' is
65, and 'B' is 66, and... (etc) and 'Z' is, er, 90, and 'a' is 97, and 'b'
is 98, and... (etc) and 'z' is 122, and the digits are 48 through 57, and
' ' is 32, and so on and so forth with all the !"%^&*()_-=+<,>.?/\\;:'~#
stuff, and if '\n' is 10 and '\r' is 13 and '\f' is 12 and so on, then the
chances are very good that it's ASCII.

Some trick for EBCDIC, but with different numbers.

Not 100% foolproof, but it may suit your needs - and if those two character
sets are your only two choices, then you can do it with a single
comparison ('A' == 65) and be assured that your result is correct.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 

 
Eric Sosman
PostPosted: Tue Sep 02, 2008 8:30 pm    Post subject: Re: detecting ASCII/EBCDIC
       
Pilcrow wrote:
Quote:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?

You could check some known chars against the EBCDIC and ASCII
numeric values:

if ('0' == 48 && 'A' == 65 && 'z' == 122 && ...)
puts ("Looks like ASCII");
else if ('0' == 240 && 'A' == 193 && 'z' == 169 && ...)
puts ("Looks like EBCDIC");
else
puts ("Now I *know* we're not in Kansas!");

It seems an uncertain business, though, because both ASCII and EBCDIC
define characters that can't be written as portable character literals
(what do you put between the '' to get EBCDIC's RSP character *and*
have it mean something on an ASCII system?), and because I don't see
how you can reliably distinguish between an ASCII system and one that
uses a more modern encoding that includes ASCII as a subset.

What's the purpose?

--
Eric.Sosman@sun.com
 

 
Default User
PostPosted: Tue Sep 02, 2008 8:32 pm    Post subject: Re: detecting ASCII/EBCDIC
       
Pilcrow wrote:

Quote:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?

You can check character values. Why do you want to?




Brian
 

 
Ben Pfaff
PostPosted: Tue Sep 02, 2008 9:09 pm    Post subject: Re: detecting ASCII/EBCDIC
       
vippstar@gmail.com writes:

Quote:
But you can check if a certain symbol has been mapped to the same
value as ASCII/EBCDIC:

#if 'A' == 65
/* A is mapped to the same value as ASCII */
#elif
/* A is not mapped to the same value as ASCII */
#endif

I don't think that's guaranteed to work, because preprocessor
directives are interpreted in the source character set, which may
differ arbitrarily from the execution character set. It could be
the case that the source character set is ASCII and the execution
character set is EBCDIC, as far as I know.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
 

 
Lew Pitcher
PostPosted: Tue Sep 02, 2008 9:29 pm    Post subject: Re: detecting ASCII/EBCDIC
       
On September 2, 2008 18:11, in comp.lang.c, Pilcrow (pilcrow@pp.info) wrote:

Quote:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?

Which EBCDIC? There are about 30 EBCDIC variants to choose from. See all the
EBCDIC-xx charts at LINK (the site of the
ISO Internationalization effort)

FWIW, the exclamation mark ('!') is 0x21 in ASCII, 0x5a in EBCDIC-US, and
0x4f in EBCDIC-INT.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
LINK | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 

 
Guest
PostPosted: Tue Sep 02, 2008 10:22 pm    Post subject: Re: detecting ASCII/EBCDIC
       
On Sep 3, 1:11 am, Pilcrow <pilc...@pp.info> wrote:
Quote:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?


No.
But you can check if a certain symbol has been mapped to the same
value as ASCII/EBCDIC:

#if 'A' == 65
/* A is mapped to the same value as ASCII */
#elif
/* A is not mapped to the same value as ASCII */
#endif

That's not telling you much though.
 

 
Antoninus Twink
PostPosted: Tue Sep 02, 2008 10:25 pm    Post subject: Re: detecting ASCII/EBCDIC
       
On 2 Sep 2008 at 22:11, Pilcrow wrote:
Quote:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?

#include <stdio.h>
#include <time.h>

int main(void)
{
time_t t;
time(&t);
if(gmtime(&t)->tm_year > 75)
puts("ASCII!");
return 0;
}
 

 
Guest
PostPosted: Tue Sep 02, 2008 10:26 pm    Post subject: Re: detecting ASCII/EBCDIC
       
On Sep 3, 1:22 am, vipps...@gmail.com wrote:
Quote:
On Sep 3, 1:11 am, Pilcrow <pilc...@pp.info> wrote:

Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?

No.
But you can check if a certain symbol has been mapped to the same
value as ASCII/EBCDIC:

#if 'A' == 65
/* A is mapped to the same value as ASCII */
#elif
^^^^

That should've been 'else'.
 

Page 1 of 5 .:. Goto page 1, 2, 3, 4, 5  Next

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

kartki świąteczne klodzko firmy kalendarze Eko Groszek rusztowania