How can I assign non-ASCII characters to a wide char and print it to the console? This code down doesn't work:
#include <stdio.h>
int main(void)
{
wchar_t wc = L'ć';
printf("%lc\n", wc);
printf("%ld\n", wc);
return 0;
}
Output:
263
Press [Enter] to close the terminal ...
I'm using MinGW GCC on Windows 7.
I think your calls to
printf()
fail with an «Illegal byte sequence» error returned inerrno
, at least that is what happens here on MacOS X with the above example code (and also if usingwprintf()
instead ofprintf()
). For me it works when I callsetlocale(LC_ALL, "");
before the call toprintf()
so that it stops using the C locale by default:It is unclear what platform/compiler you are on, so YMMV.
You should use
wprintf
to print wide-character strings:use wprintf("%lc\n" ,wc); and you will get your desired output