I am trying to output things like 안, 蠀, ☃ from C
#include <wchar.h>
int main()
{
fwprintf(stdout, L"안, 蠀, ☃\n");
return 0;
}
output is ?, ?, ?
How do I print those characters?
Edit:
#include <wchar.h>
#include <locale.h>
int main()
{
setlocale(LC_CTYPE, "");
fwprintf(stdout, L"안, 蠀, ☃\n");
return 0;
}
this did the trick. output is 안, 蠀, ☃ . except that the chinese character and snowman appears as box in my urxvt probably because I did not enable those locales.
$ locale -a
C
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8
ja_JP.utf8
ko_KR
ko_KR.euckr
ko_KR.utf8
korean
korean.euc
POSIX
zh_CN.utf8
which locale do I have to enable additionally so that it'll display chinese character and snowman? maybe do I need font?
will the above program work on Windows?
You have to set your output terminal as Unicode compatible.
On Linux (with Bash shell), try:
$ LANG=en.UTF-8
and also make sure that your terminal emulator can actually display Unicode and is configured to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With