Reputation: 575
I've written a 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 this print the character ┐
?
Instead it prints gibberish.
I've checked:
Upvotes: 4
Views: 1254
Reputation: 301
wprintf
is a version of printf
which takes a wide string as its format string, but otherwise behaves just the same: %c
is still treated as char
, not wchar_t
. So instead you need to use %lc
to format a wide character. And since your strings are ASCII you may as well use printf
. For example:
int main() {
printf("%s\n", setlocale(LC_ALL, "C.UTF-8"));
wchar_t chr = L'┐';
printf("%lc\n", chr);
}
Upvotes: 6