Displaying special characters with Chinese Locale in c

594 views Asked by At

I have a requirement to adapt an existing, non-unicode, c project to display Chinese characters.  As there is a short deadline, and I'm new(ish) to C and encoding I've gone down the route of changing the sytem locale to Simplified Chinese PRC in order to support display of Chinese text in the gui application.  This has in turn changed the encoding (in visual studio 2010) in the project to Chinese Simplified (GB2312).

Everything works except that special characters, eg: degree sign, superscript 2, etc are displayed as question marks.  I believe this is because we used to pass \260 i.e. the octal value of the degree symbol in the ascii table, and this no longer equates to anything in the gb2312 table. 

The workflow for displaying a degree symbol in a keypad was as follows: 

display_function( data, '\260' ); //Pass the octal value of the degree symbol to the keypad 

This display_function is used to translate the integer inputs into strings for display on the keypad: 

data->[ pos ] = (char) ch; 

Essentially I need to get this (and other special chars) to display correctly.  Is there a way to pass this symbol using the current setup? 

According to the char list for gb23212 the symbol is supported so my current thinking is to work out the octal value of the symbol and keep the existing functions as they are.  These currently pass the values around as chars.  Using the table below: 

http://ash.jp/code/cn/gb2312tbl.htm

and the following formula to obtain the octal value: 

octal number associated with the row, multiplied by 10 and added to the octal number associated with the column. 

I believe this would be A1E0 x 10 + 3 = 414403. 

However, when I try and pass this to display_function I get "error C2022: '268' : too big for character".

Am I going about this wrong?  I'd prefer not to change the existing functions as they are in widespread use, but do I need to change the function to use a wide char? 

Apologies if the above is convoluted and filled with incorrect assumptions!  I've been trying to get my head round this for a week or two and encodings, char sets and locales just seem to get more and more confusing!

thanks in advance

1

There are 1 answers

0
AlexL On

If current functions support only 8-bits characters, and you need to use them to display 16-bits characters, then probably your guess is correct - you may have to change functions to use something like "wchar" instead of "char".

Maybe also duplicate them with other name to provide compatibility for other users in case these functions are used in other projects.

But if it's only one project, then maybe you will want to check possibility to replace "char" by "wchar" in almost all places of the project.