![]() |
|
(non-allegro) How do I handle non-american characters in a console application? |
emilb
Member #7,146
April 2006
![]() |
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
![]() |
-- |
TeamTerradactyl
Member #7,733
September 2006
![]() |
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
![]() |
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? 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
![]() |
You need to somehow get the encoding right. UTF8, Windows, DOS, Apple, whatever it is... --- |
TeamTerradactyl
Member #7,733
September 2006
![]() |
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 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
![]() |
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: 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: |
|