First of all, I'm very sorry if there is a thread which completely solves my problem. I did try to use the search utility but I may not have done so properly.
What I am trying to accomplish in C is simple. At least, it sounds simple. All I want to do is output Russian characters. By now I've spent 5 or 6 hours trying to figure out how to do this but so far I've been unsuccessful. I've read the Unicode tutorial several times but, as I'm a bit of a novice, I don't quite understand everything which is being said. Also, it seems to me that that tutorial is focused on updating code to make it Unicode friendly, instead of creating something new which is specifically geared towards manipulating Unicode characters.
I guess what I'll do is post the pathetic bit of code I have written and explain how I arrived at the individual lines.
1. wchar_t dest;Code:#include <stdio.h> #include <locale.h> #include <wchar.h> int main() { wchar_t dest; setlocale(LC_ALL, "ru-RU"); mbrtowc(&dest, "Б", 4, NULL); wprintf(L"%Lc\n", dest); wprintf(L"Б\n"); printf("Б\n"); }
In the Unicode tutorial, it's recommended not to use this type of variable but I decided to try it anyway since I couldn't get anything else to work.
2. setlocale(LC_ALL, "ru-RU");
From what I understand, I need to include this line because the environment which supports the execution of my code may not otherwise be expecting Russian characters. (Fair enough.) The locale name I'm using may be incorrect. (Does anyone know?)
3. mbrtowc(&dest, "Б", 4, NULL); wprintf(L"%Lc\n", dest);
This is my first attempt at outputting a character. In the first line, I'm trying to convert the symbol into a wide character. As previously mentioned, I am a bit of a novice so I'm not entirely sure whether or not I've filled in the fields properly. I used 4 for the size because I read that UTF-8 can require up to 4 bytes.
4. wprintf(L"Б\n");
My second attempt, without the conversion.
5. printf("Б\n");
My third attempt. I really don't expect this one to work but I've included it anyway.
Hopefully someone can tell me what it is I'm doing wrong and steer me in the right direction. I'd really like to learn how to properly use Unicode in my programming but I fear I've already spent too many hours in the pursuit...
By the way, I'm using Windows 7.