View previous topic :: View next topic |
Author |
Message |
OdinsDream Veteran
Joined: 01 Jun 2002 Posts: 1057
|
Posted: Sun Dec 15, 2002 3:07 am Post subject: Change from ISO Latin 1 to ASCII characterset? |
|
|
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 |
|
|
choward Tux's lil' helper
Joined: 08 Nov 2002 Posts: 92
|
Posted: Mon Dec 16, 2002 3:51 pm Post subject: |
|
|
%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 |
|
|
OdinsDream Veteran
Joined: 01 Jun 2002 Posts: 1057
|
Posted: Mon Dec 16, 2002 5:31 pm Post subject: |
|
|
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 |
|
|
choward Tux's lil' helper
Joined: 08 Nov 2002 Posts: 92
|
Posted: Mon Dec 16, 2002 6:01 pm Post subject: |
|
|
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 |
|
|
OdinsDream Veteran
Joined: 01 Jun 2002 Posts: 1057
|
Posted: Mon Dec 16, 2002 6:43 pm Post subject: |
|
|
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 |
|
|
choward Tux's lil' helper
Joined: 08 Nov 2002 Posts: 92
|
|
Back to top |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20067
|
Posted: Mon Dec 16, 2002 10:10 pm Post subject: |
|
|
What setting(s) do you have in your kernel for File systems, Native Language Support ? _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
OdinsDream Veteran
Joined: 01 Jun 2002 Posts: 1057
|
Posted: Tue Dec 17, 2002 3:24 am Post subject: |
|
|
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 |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20067
|
Posted: Tue Dec 17, 2002 4:00 am Post subject: |
|
|
Probably not. Was just a shot in the dark. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
OdinsDream Veteran
Joined: 01 Jun 2002 Posts: 1057
|
Posted: Tue Dec 17, 2002 6:23 am Post subject: |
|
|
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 |
|
|
choward Tux's lil' helper
Joined: 08 Nov 2002 Posts: 92
|
Posted: Tue Dec 17, 2002 3:41 pm Post subject: |
|
|
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 |
|
|
Lion Apprentice
Joined: 23 Jun 2002 Posts: 207
|
Posted: Tue Dec 17, 2002 7:19 pm Post subject: |
|
|
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 |
|
|
|