Search code examples
cunicodesetlocale

Printing Japanese characters in C program


I want to print Japanese characters using the C program. I've found the Unicode range of some Japanese characters, converted them to decimal and used the for loop to print them:

setlocale(LC_ALL, "ja_JP.UTF8");
for (int i = 12784; i <= 12799; i++) {
  printf("%c\n",i);
}

locale.h and wchar.h are present in the header.

The output gives me only ?????????? characters.

Please let me know how it could be resolved.


Solution

  • %c is only able to print characters from 0 to 127, for extended characters use:

    printf("%lc\n", i);
    

    or better yet

    wprintf(L"%lc\n", i);