Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » (non-allegro) How do I handle non-american characters in a console application?

This thread is locked; no one can reply to it. rss feed Print
(non-allegro) How do I handle non-american characters in a console application?
emilb
Member #7,146
April 2006
avatar

I am building a console application in Dev C++, which does some operations on words that are either input from keyboard or read from files.

It's a very basic program with mostly char arrays and comparison between them.

All it does is compare the char values contained in these words, for example it could ask you for a password to enter the program and then check in a data file if the password is correct.

I have 1 problem with this: I live in Sweden and we use some characters that are non-american, such as å ä ö. The program cannot handle this, instead these characters become strange other things.

I have also seen that é for example, becomes Ú when input into the program.

It seems that every character that the program cannot handle, has a specific character that it becomes instead (as with é above), so it would probably be possible to handle each such character by itself and convert inside the program (that is, if I recieve an é, it becomes an Ù but then I can change it back with error checking inside the program).

But that's quite a bit of work looking up every specific character.

Is there some way to make the program support non-english characters by #include a file or something to do this?

Thanks for your help,

Emil

gnolam
Member #2,030
March 2002
avatar

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

TeamTerradactyl
Member #7,733
September 2006
avatar

emilb, it is like gnolam said. What's happening is that your program is trying to calculate your input as ASCII, where you should actually be using Unicode so it can calculate the region code (ie Swedish).

emilb
Member #7,146
April 2006
avatar

Thanks for telling me this.

I am currently not using allegro in this project, but I suppose I can do it and still be in the console and do the same things.

Is there a way to be able to do this without using allegro, though?
The original program was only running in the console with iostream and fstream loaded, and I started making tables of characters on my own, to be able to repair the char* arrays that were in bad condition after entering åäö and similar things.

I'll try this with allegro and see if I can make it work in the console, without changing the gfx mode.

Tobias Dammers
Member #2,604
August 2002
avatar

You need to somehow get the encoding right. UTF8, Windows, DOS, Apple, whatever it is...

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

TeamTerradactyl
Member #7,733
September 2006
avatar

I know that cppreference.com talks about wchar_t, and so I don't know if that's what you're looking for:

http://www.cppreference.com/data_types.html
or
http://www.cppreference.com/keywords/wchar_t.html

You may try defining your input as type wchar_t and doing a cin >> or whatever. On the "data_types" page, however, it mentions that it's newly introduced to C++ (not C).

Matt Smith
Member #783
November 2000

Does the Windows console use unicode? I thought it still used DOS code-pages. I think you need a Swedish system.fnt

torhu
Member #2,727
September 2002
avatar

I assume you are on Windows. Then your source code is probably in Windows-1252, and your console likely uses code page 850.

Both code pages are listed here:
http://en.wikipedia.org/wiki/Western_Latin_character_sets_%28computing%29#Comparison_table

You just need two arrays to convert back and forth between these encodings. The data you need is probably on the web somewhere, so you don't have to type it out yourself. I haven't had the need to do this myself, so I can't tell the quickest way to get this working.

The iconv lib supposedly can do this.

http://gnuwin32.sourceforge.net/packages/libiconv.htm

Online docs here:
http://www.gnu.org/software/libiconv/

Go to: