Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Change from ISO Latin 1 to ASCII characterset?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
OdinsDream
Veteran
Veteran


Joined: 01 Jun 2002
Posts: 1057

PostPosted: Sun Dec 15, 2002 3:07 am    Post subject: Change from ISO Latin 1 to ASCII characterset? Reply with quote

I'm trying to code a project in C, and my output is with printf():

printf(" %c", 201);

which should print the top-left-corner double pipe symbol. According to www.asciitable.com, which I've used before to do similar work using

cout << char(201);


However, the above printf statement outputs a capital, accented E on my system. asciitable.com shows this accented E to be number 144.

What table can I rely on? Is there a way to switch the characterset on the system I'm developing, to use the same codes I find on asciitable.com ?


Last edited by OdinsDream on Mon Dec 16, 2002 5:47 pm; edited 1 time in total
Back to top
View user's profile Send private message
choward
Tux's lil' helper
Tux's lil' helper


Joined: 08 Nov 2002
Posts: 92

PostPosted: Mon Dec 16, 2002 3:51 pm    Post subject: Reply with quote

%c prints a signed character by default. You have a few options (I'm not sure which one works):
1. %uc
2. %C
3. wprintf(" %c", 201 );
_________________
Craig Howard
4B Computer Science -- University of Waterloo
Back to top
View user's profile Send private message
OdinsDream
Veteran
Veteran


Joined: 01 Jun 2002
Posts: 1057

PostPosted: Mon Dec 16, 2002 5:31 pm    Post subject: Reply with quote

choward wrote:
%c prints a signed character by default. You have a few options (I'm not sure which one works):
1. %uc
2. %C
3. wprintf(" %c", 201 );


Thanks for the post, but neither of these seem to work. I don't see mention of the %uc formatting string in my ANSI C book, nor capital C. Using these just doesn't cause anything to print. wprintf also prints nothing.

Anything else I could try?

Edit:

Using this code:
Code:

  /* Demonstrates printing extended ASCII characters */

  #include <stdio.h>

  unsigned char x;    /* Must be unsigned for extended ASCII */

  main()
  {
      /* Print extended ASCII characters 180 through 203 */

     for (x = 180; x < 204; x++)
     {
         printf("\nASCII code %d is character %c", x, x);
     }
 }


I've printed out the extended character set on my system. It's entirely different from that used on asciitable.com. No "frame" characters are available. I'm attempting to create menus and boxes, but without these characters, how can I go about that?

Interestingly enough, it seems that printf("%c", 201); will work after all. Now I just need to figure out why my system has different extended sets.

Edit:
After some more browsing on google, it looks like the characterset displayed by the above code belongs to "ISO Latin 1", instead of ASCII.

How can I get my system to use ASCII codes instead of ISO Latin 1?
Back to top
View user's profile Send private message
choward
Tux's lil' helper
Tux's lil' helper


Joined: 08 Nov 2002
Posts: 92

PostPosted: Mon Dec 16, 2002 6:01 pm    Post subject: Reply with quote

OdinsDream wrote:
I've printed out the extended character set on my system. It's entirely different from that used on asciitable.com. No "frame" characters are available. I'm attempting to create menus and boxes, but without these characters, how can I go about that?

Have you investigated ncurses?
_________________
Craig Howard
4B Computer Science -- University of Waterloo
Back to top
View user's profile Send private message
OdinsDream
Veteran
Veteran


Joined: 01 Jun 2002
Posts: 1057

PostPosted: Mon Dec 16, 2002 6:43 pm    Post subject: Reply with quote

I have, its a little more complex than I need. I just want to print a nice-looking checkers board for a project.

How can I get the ASCII character set?
Back to top
View user's profile Send private message
choward
Tux's lil' helper
Tux's lil' helper


Joined: 08 Nov 2002
Posts: 92

PostPosted: Mon Dec 16, 2002 8:59 pm    Post subject: Reply with quote

All I can do at this point is pass you over to the glibc documentation:
http://www.gnu.org/manual/glibc-2.2.5/html_node/index.html
_________________
Craig Howard
4B Computer Science -- University of Waterloo
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20067

PostPosted: Mon Dec 16, 2002 10:10 pm    Post subject: Reply with quote

What setting(s) do you have in your kernel for File systems, Native Language Support ?
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
OdinsDream
Veteran
Veteran


Joined: 01 Jun 2002
Posts: 1057

PostPosted: Tue Dec 17, 2002 3:24 am    Post subject: Reply with quote

kanuslupus wrote:
What setting(s) do you have in your kernel for File systems, Native Language Support ?


Default NLS Option: "iso8859-1"

No other modules are installed. Should I change this?
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20067

PostPosted: Tue Dec 17, 2002 4:00 am    Post subject: Reply with quote

Probably not. Was just a shot in the dark.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
OdinsDream
Veteran
Veteran


Joined: 01 Jun 2002
Posts: 1057

PostPosted: Tue Dec 17, 2002 6:23 am    Post subject: Reply with quote

Another interesting note...

I've been working in an Eterm window inside an X session, and that's where I've been testing code. If, however, I switch to a virtual console, the character set is entirely different.

I then have available the "graphical" characters I need to draw the boxes.

HOWEVER, these characters still don't match any tables I've seen on the web.

My concern is, how can I have any idea how my code will run on other systems?
Back to top
View user's profile Send private message
choward
Tux's lil' helper
Tux's lil' helper


Joined: 08 Nov 2002
Posts: 92

PostPosted: Tue Dec 17, 2002 3:41 pm    Post subject: Reply with quote

OdinsDream wrote:
kanuslupus wrote:
What setting(s) do you have in your kernel for File systems, Native Language Support ?


Default NLS Option: "iso8859-1"

No other modules are installed. Should I change this?

Good one kanuslupus. ASCII corresponds to cp437. This seems like a far from portable solution though.
_________________
Craig Howard
4B Computer Science -- University of Waterloo
Back to top
View user's profile Send private message
Lion
Apprentice
Apprentice


Joined: 23 Jun 2002
Posts: 207

PostPosted: Tue Dec 17, 2002 7:19 pm    Post subject: Reply with quote

choward wrote:

Good one kanuslupus. ASCII corresponds to cp437. This seems like a far from portable solution though.


AFAIK, ASCII only defines characters 0-127.
Everything else is an extension, and varies according to which locale / codepage (MSDOS speak) you have selected.

Usually, a USA PC will use codepage 437 (which contains line drawing characters) by default, but this is overridden as soon as the OS is loaded. Here in The Netherlands, Windows uses 850 by default, so you don't have the line drawing characters any more.

To make a long story short: if you need portability, go for ncurses.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum