Go Back   Forums > Community Chatterbox > Tech Corner
Memberlist Forum Rules Search Today's Posts Mark Forums Read
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 03-09-2013, 04:26 PM   #11
Mighty Midget
Pox Vobiscum
 
Mighty Midget's Avatar


 
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
Default

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
Mighty Midget is offline                         Send a private message to Mighty Midget
Reply With Quote
Old 03-09-2013, 06:07 PM   #12
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,565
Default

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...
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 03-09-2013, 06:13 PM   #13
The Fifth Horseman
FUTURE SCIENCE BASTARD
 
The Fifth Horseman's Avatar


 
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,268
Default

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.
__________________

"God. Can't you people see I'm trying to commit a crime against science and nature here?"
-- Reed Richards
The Fifth Horseman is offline                         Send a private message to The Fifth Horseman
Reply With Quote
Old 03-09-2013, 07:50 PM   #14
Mighty Midget
Pox Vobiscum
 
Mighty Midget's Avatar


 
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
Default

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 07:54 PM.
Mighty Midget is offline                         Send a private message to Mighty Midget
Reply With Quote
Old 03-09-2013, 08:06 PM   #15
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,565
Default

Again, the codes that start with 0 on the Windows charmap are NOT ASCII.

http://en.wikipedia.org/wiki/ASCII
Quote:
Not to be confused with MS Windows-1252, also known as "ANSI", or other types of Extended ASCII, often just called "ASCII".

The American Standard Code for Information Interchange (ASCII) is a character-encoding scheme originally based on the English alphabet that encodes 128 specified characters
See attachments.

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.
Attached Images
File Type: png qbasic_000.png (12.2 KB, 1 views)
File Type: png qbasic_001.png (11.1 KB, 1 views)
__________________
Life starts every day anew. Prospects not so good...
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 03-09-2013, 08:34 PM   #16
Mighty Midget
Pox Vobiscum
 
Mighty Midget's Avatar


 
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
Default

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
Mighty Midget is offline                         Send a private message to Mighty Midget
Reply With Quote
Old 03-09-2013, 10:34 PM   #17
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,565
Default

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 10:43 PM.
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 03-09-2013, 11:25 PM   #18
The Fifth Horseman
FUTURE SCIENCE BASTARD
 
The Fifth Horseman's Avatar


 
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,268
Default

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");
__________________

"God. Can't you people see I'm trying to commit a crime against science and nature here?"
-- Reed Richards
The Fifth Horseman is offline                         Send a private message to The Fifth Horseman
Reply With Quote
Old 03-09-2013, 11:29 PM   #19
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,565
Default

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 wrld! %s",
	L'' == L'\u00f8' ? L"True" : L"False");
To change the console mode from ANSI to Unicode (solving the / confusion), apparently you can do this:

Code:
#include <io.h>
#include <fcntl.h>
Code:
_setmode(_fileno(stdout), _O_U16TEXT);
Make sure though that the font used by your console window does have those strange characters. It's not the case by default in my case, but you can right-click on the console window title bar and go to choose properties > font tab. Then restart your program, because the font will have transformed the strange characters to ? or normal letters before outputting them. (See how pointless all this is...!)
__________________
Life starts every day anew. Prospects not so good...

Last edited by Japo; 03-09-2013 at 11:53 PM.
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 04-09-2013, 12:30 AM   #20
jonh_sabugs
Abandonia nerd

 
Join Date: May 2010
Location: Brazil
Posts: 91
Default

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.
jonh_sabugs is offline                         Send a private message to jonh_sabugs
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
EoF Corner Eagle of Fire Offers 6 03-02-2010 06:01 PM
The end of the file corner Eagle of Fire Music, Art, Movies 8 08-12-2009 01:09 AM
Spoonman's Art Corner Spoonman Music, Art, Movies 122 15-01-2009 10:35 PM
Spoonman's Music Corner Spoonman Music, Art, Movies 3 25-06-2005 06:18 PM

Thread Tools
Display Modes

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
Forum Jump
 


The current time is 11:20 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.