Printing Japanese Characters in C Program - Stack Overflow
Printing Japanese Characters in C Program - Stack Overflow
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);
}
2 Does your font include Japanese characters? – domsson May 1 '20 at 9:38
Add a comment
%c is only able to print characters from 0 to 127, for extended characters use:
4
printf("%lc\n", i);
or better yet
wprintf(L"%lc\n", i);
Can you try with setlocale(LC_ALL, ""); ? it works for me: ideone.com/AFX4DK , also, as pointed out by
@domsson in comments: check if your console font supports japanese graphs. – David Ranieri May 1 '20 at 9:56
setlocale(LC_ALL, "") has fixed the issue. Thank you very much! The last question. I thought it was needed to specify
what locale I want to use, so I used ja_JP.UTF8. I'm just interested why setlocale(LC_ALL, "") works as well. – Карина
Баринова May 1 '20 at 10:02
Add a comment
In addition @David Ranieri fine answer, I wanted to explain about the "output gives me only
2
?????????? characters."
"%c" accepts an int argument. Recall a char passed to a ... function is converted to an
int . Then
the int argument is converted to an unsigned char , and the resulting character is
written. C17dr § 7.21.6.1 8.
Thus printf("%c" ... handles values 0-255. Values outside that range being converted to
that range.
With OP locale setting and implementation, printing values [0xF0 - 0XFF] resulted in '?' . I am
confident that is true for [0x80 - 0xFF] for OP. Other possibilities exist. I received � .
Had OP done the below, more familiar output would be seen, though not the Hiragana
characters desired.
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Your Answer
Body
Add picture
Log in
OR
Name
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
meta chat tour help blog privacy policy legal contact us full site
2021 Stack Exchange, Inc. user contributions under cc by-sa