c - Why Unicode characters are not displayed properly in terminal with GCC? -
i've written small c program:
#include <stdio.h> #include <stdlib.h> #include <locale.h> int main() { wprintf(l"%s\n", setlocale(lc_all, "c.utf-8")); wchar_t chr = l'┐'; wprintf(l"%c\n", chr); }
why doesn't print character ┐
?
instead prints gibberish.
i've checked:
- tried compiling without setlocale, same result
- the terminal can print character, can copy-paste terminal text-editor, it's gnome-terminal on ubuntu
- gcc version 4.8.2
wprintf
version of printf
takes wide string format string, otherwise behaves same: %c
still treated char
, not wchar_t
. instead need use %lc
format wide character. , since strings ascii may use printf
. example:
int main() { printf("%s\n", setlocale(lc_all, "c.utf-8")); wchar_t chr = l'┐'; printf("%lc\n", chr); }
Comments
Post a Comment