TremorBlue
asked on
How to represent a russian string ( unicode ) in a C string..
I need to store russian months in an array ?
I am working on an older embedded project and need to represent Russian months in c source code. With this processor the characters are 16bits so I can put unicoode characters in them.
But all the string functions are 8bits. If I enter the unicode characters in the IDE I get ???? instead.
static const char*sEnglishNames[13] ={"","January","February", "March","A pril","May ",
"June","July","August","Se ptember"," October"," November", "December"};
Russian months
¿¿¿¿¿¿ - January
¿¿¿¿¿¿¿ - February
¿¿¿¿ - March
¿¿¿¿¿¿ - April
¿¿¿ - May
¿¿¿¿ - June
¿¿¿¿ - July
¿¿¿¿¿¿ - August
¿¿¿¿¿¿¿¿ - September
¿¿¿¿¿¿¿ - October
¿¿¿¿¿¿ - November
¿¿¿¿¿¿¿ - December
I am working on an older embedded project and need to represent Russian months in c source code. With this processor the characters are 16bits so I can put unicoode characters in them.
But all the string functions are 8bits. If I enter the unicode characters in the IDE I get ???? instead.
static const char*sEnglishNames[13] ={"","January","February",
"June","July","August","Se
Russian months
¿¿¿¿¿¿ - January
¿¿¿¿¿¿¿ - February
¿¿¿¿ - March
¿¿¿¿¿¿ - April
¿¿¿ - May
¿¿¿¿ - June
¿¿¿¿ - July
¿¿¿¿¿¿ - August
¿¿¿¿¿¿¿¿ - September
¿¿¿¿¿¿¿ - October
¿¿¿¿¿¿ - November
¿¿¿¿¿¿¿ - December
Works for me copy & pasting the Russian names. Note however, that your unicode strings are going to be wchar_t* and not char*, unicode string literals are prefixed with "L", and you need to make sure your editor will save your source code file as unicode.
wchar_t *sRussianMonths[3] = { L"¿¿¿¿¿¿", L"¿¿¿¿¿¿¿", L"¿¿¿¿"};
Well, I guess EE doesn't support Unicode strings. ;)
Maybe if I don't put it in a code block...
wchar_t *sRussianMonths[3] = { L"¿¿¿¿¿¿", L"¿¿¿¿¿¿¿", L"¿¿¿¿"};
Maybe if I don't put it in a code block...
wchar_t *sRussianMonths[3] = { L"¿¿¿¿¿¿", L"¿¿¿¿¿¿¿", L"¿¿¿¿"};
wchar_t is very platform dependent, and is not guaranteed to be able to store the Unicode character you try to put in it. So, it is not recommended to use it if you need Unicode support in your application - especially not if you'd like that Unicode support to be portable.
Instead, use an external library like the one I suggested earlier.
Instead, use an external library like the one I suggested earlier.
Agreed, http:#a35439793 is the better approach - I had just left the window sitting open for a few minutes and so didn't see your comment before I hit submit. ;)
An open window is good !! Brings in fresh air :)
ASKER
Yes but forget about experts exchange I don't mind that it doesnt work there.
I want to know how to do unicode strings inside an old ccompiler.
I was thinking about just using the unicode numbers .. ?
I want to know how to do unicode strings inside an old ccompiler.
I was thinking about just using the unicode numbers .. ?
Please refer to my first reply ;)
how old is the c compiler?
can you check whether the below compiles
and if yes tell whether it prints correctly?
Sara
can you check whether the below compiles
#include <stdio.h>
int main()
{
wchar_t * pws = L"January";
int szwc = sizeof(wchar_t);
wprintf(L"%s %d", pws, szwc);
return 0;
}
and if yes tell whether it prints correctly?
Sara
ASKER
The compiler does not support wchar_t.
I don't need to have a library like ICU.
As my question says I just need to store the unicode characters in an array.
It looks like I have to store the characters in an array of shorts.
I don't need to have a library like ICU.
As my question says I just need to store the unicode characters in an array.
It looks like I have to store the characters in an array of shorts.
>> As my question says I just need to store the unicode characters in an array.
So you don't ever want to display them ?
Can you be sure that all unicode characters you'll ever use will be (exactly) 16 bits wide ?
So you don't ever want to display them ?
Can you be sure that all unicode characters you'll ever use will be (exactly) 16 bits wide ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forgot the final instructions - create an array of points that are indexed into the array above. This can be done automatically at runtime by searching for the spaces, which you'll then want to turn into zeros so that the strings are null terminated. (Also, my sample array needs ,0x00,0x00 at the end to terminate it properly.)
One thing you have to be careful of is that you have to read the file and write the result as bytes, not as shorts, otherwise you'll have problems on little-endian architectures.
One thing you have to be careful of is that you have to read the file and write the result as bytes, not as shorts, otherwise you'll have problems on little-endian architectures.
ASKER
http://www.russianlessons.net/vocabulary/nouns_days.php