My C program is pasted below. In bash, the program print “char is “, Ω
is not printed. My locale are all en_US.utf8.
#include <stdio.h>
#include <wchar.h>
#include <stdlib.h>
int main() {
int r;
wchar_t myChar1 = L'Ω';
r = wprintf(L"char is %c\n", myChar1);
}
This was quite interesting. Apparently the compiler translates the omega from UTF-8 to UNICODE but somehow the libc messes it up.
First of all: the
%c-format specifier expects achar(even in the wprintf-version) so you have to specify%lc(and therefore%lsfor strings).Secondly if you run your code like that the locale is set to
C(it isn’t automatically taken from the environment). You have to callsetlocalewith an empty string to take the locale from the environment, so the libc is happy again.