C programming, unicode and linux terminal

So, I'm trying to write Japanese characters to my terminal using C and wide characters.

The question is what happened to what I'm doing so that I can fix it, what other reservations should I expect when using wide characters and do you have any comments on what I'm trying to do?




Bad code:

#include <stdio.h>
#include <wchar.h>

int main( ) {
    wprintf(L"%c\n", L"\x3074");
}

This does not work, but I want to know why.


the problem only gets worse when I try to use wchar_t to store the value:

wchar_t pi_0 = 0x3074;      // prints a "t" when used with wprintf
wchar_t pi_1 = "\x3074";    // gives compile time warning
wchar_t pi_2 = L"\x3074";   // gives compile time warning

Therefore, I would also like to do this work, since I plan to have data structures by holding lines of these characters.




Thank!

+3
source share
2 answers

"\x3074" - const char[], L"\x3074" - const wchar_t[].

wchar_t, :

L'\x3074'

%c a char, wchar_t %lc.

+10

.

  • ,
  • - , setlocale()

( , - Unicode - , , , Linux, ).

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main( ) {
    setlocale(LC_ALL, "");
    wprintf(L"%ls\n", L"\x0152\x3074");
    return 0;
}

. , setlocale() wprint().

( U + 0152, OE, , U + 3074)

+4

Source: https://habr.com/ru/post/1732063/


All Articles