03-09-2013, 03:26 PM | #11 | ||
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
|
Ok, here's a good Q about ASCII codes:
If I hold down left tab and type 248, I get ° If I hold down left tab and type 0248 I get ø I'm trying to have this program type out an ø but starting a decimal number with 0 is not going to work so any idea how I can have the program print out an ø and not a °?
__________________
Je Suis Charlie |
||
|
|
03-09-2013, 05:07 PM | #12 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
Short answer: there's no way to print "ø" with the standard library. You're barking at the wrong door. Either you want a simple console C program, or you want to print strange characters. You can of course switch to a graphic mode (again not in the standard library) and use some font library. My advice is that you continue your C learning with interesting programs that are practical to write in C, not these pointless bells and whistles, you won't learn anything useful, let alone nowadays. Use "oe" instead etc.
Forget about "°", it's completely unrelated. Windows extended the number of characters that you can create with the numpad in that way, but that doesn't mean that the ASCII character "x" has any relationship with the character "0x". You just get sixteen times as many possible codes or characters. Portable C (the standard library) supports ASCII characters (0-255) only--and be careful with the extended set (from 128 to the final end 255--see below why). Nowadays there are simpler ways to get international characters as well as fancy windows and whatnot. Nobody uses the console, and when they do, they don't ask it to display funny stuff. Back in the day MS-DOS came up with a way to print international characters on the console: the commands "MODE con codepage prepare" and "... select". Since there are many more than it's not possible to get all international characters. IIRC these commands replace the standard extended set (128-255) with country-specific characters (you select the country when you call the command, you can't have all characters at once). On the other hand, this would break the display of programs that rely on the standard extended ASCII set. Moreover, the MODE command is specific to MS-DOS; for example it doesn't come with DOSBox.
__________________
Life starts every day anew. Prospects not so good... |
||
|
|
03-09-2013, 05:13 PM | #13 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
The first as ASCII 0xF8. The second is Unicode 0x00F8.
Option A, figure out a way to output unicode instead of ASCII. Option B, figure out which codepage you should be using in order for 0xF8 to map to ø and how to switch to that codepage. |
||
|
|
03-09-2013, 06:50 PM | #14 | ||
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
|
I have it working perfectly for both å and æ, but not for ø. ASCII for å and æ both start with a non-0 and it works. The thing is ø starts with a 0, withouth the zero it's the code for a plain o.
What I'm not getting is why å and æ are ok but ø has a "useless" code. I wrote a program to give me the ascii values for any sign and for all but ø it worked. For ø I got the value for o. As for the whys and all that, this is a school assignment so style and reason are irrelevant I guess.
__________________
Je Suis Charlie Last edited by Mighty Midget; 03-09-2013 at 06:54 PM. |
||
|
|
03-09-2013, 07:06 PM | #15 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
Again, the codes that start with 0 on the Windows charmap are NOT ASCII.
http://en.wikipedia.org/wiki/ASCII Quote:
You'd need to change codepage--which is a platform-dependent operation when available. Honestly if I were you I'd be studying interesting algorithms instead of doing archeology in the museum of horrors.
__________________
Life starts every day anew. Prospects not so good... |
||
|
|
03-09-2013, 07:34 PM | #16 | ||
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
|
If I were you, I'd see it the same way but unfortunately, this assignment is pretty well defined and is going in for review.
__________________
Je Suis Charlie |
||
|
|
03-09-2013, 09:34 PM | #17 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
OMG, it reminds me when in college they made us program a database from scratch with binary files. Who wants to use already available and specially designed tools like SQL? Some teachers seem to think that it's more educative to make a wheel with clay than to build a working bicycle with available materials and less effort.
And localization is so important for beginning programmers to learn... Or for anyone for that matter... In what platform must you do this? Windows? What compiler must you use or are you using? What libraries are you allowed to use?
__________________
Life starts every day anew. Prospects not so good... Last edited by Japo; 03-09-2013 at 09:43 PM. |
||
|
|
03-09-2013, 10:25 PM | #18 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
Look at it this way: your software is outputting the correct code. Your shell is using a codepage where the character maps to something else than it should. The simple solution is to change the codepage such as by calling system("CHCP 1142");
|
||
|
|
03-09-2013, 10:29 PM | #19 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
Hmm it's been a while since I learned C... Apparently (of course) Unicode is now part of the standard library. See versions of standard functions that include the letter w, for example:
http://msdn.microsoft.com/en-us/library/wc7014hz.aspx Wide char strings are made of wchar_t instead of char, and their literals are preceded with an L: Code:
wprintf(L"Hell\u00f8 wørld! %s", L'ø' == L'\u00f8' ? L"True" : L"False"); Code:
#include <io.h> #include <fcntl.h> Code:
_setmode(_fileno(stdout), _O_U16TEXT);
__________________
Life starts every day anew. Prospects not so good... Last edited by Japo; 03-09-2013 at 10:53 PM. |
||
|
|
03-09-2013, 11:30 PM | #20 | ||
Join Date: May 2010
Location: Brazil
Posts: 91
|
I don't think wchar_t and unicode strings are part of standard C library, only C++. I know that compilers such as GCC do not implement wchar family for C code.
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
EoF Corner | Eagle of Fire | Offers | 6 | 03-02-2010 05:01 PM |
The end of the file corner | Eagle of Fire | Music, Art, Movies | 8 | 08-12-2009 12:09 AM |
Spoonman's Art Corner | Spoonman | Music, Art, Movies | 122 | 15-01-2009 09:35 PM |
Spoonman's Music Corner | Spoonman | Music, Art, Movies | 3 | 25-06-2005 05:18 PM |
|
|
||
  |