Home > database >  My windows C program does not print japanese characters
My windows C program does not print japanese characters

Time:07-03

#include <locale.h>
#include <stdio.h>
#include <wchar.h>
 
 
int main() {
  setlocale(LC_ALL, "");
  wchar_t test = L'づ';

  printf("%ls", L"\x3065");
  printf("%lc", test);

  return 0;     
}

the expected output is: づづ, but these two printf does not print anything, what can i do to solve this problem?

CodePudding user response:

printf is a narrow string function and unless you have requested UTF-8 in your manifest and are running on an appropriate version Windows 10 it is not going to print Unicode correctly in all cases.

Use wprintf to print wide strings. Depending on the C runtime library, you might need to call _setmode(_fileno(stdout), _O_U16TEXT); first before printing.

Even if your program does everything correctly it might still not work in the console. Using the new Windows Terminal should work. The older console might just display squares. This is a console/font limitation. Copy the squares to the clipboard and paste in Wordpad to see that your program actually worked correctly.

See also:

  • Related