Consider the following program:
#include <stdio.h>
#include <string.h>
int main() {
char* alpha = "Ω";
fwrite(alpha, 1, strlen(alpha), stdout);
return 0;
}
On Windows I get the following output:
��
I tried changing the line to this:
char* alpha = "zΩ";
and it prints correctly. The output is encoded correctly, just not printing correctly:
$ bad | od -tx1c 0000000 ce a9 316 251 $ good | od -tx1c 0000000 7a ce a9 z 316 251
How can I use fwrite with non ASCII as the first character?
To response to some comments: The source file is correctly formatted as UTF-8, and my code page is also correctly set as UTF-8:
$ chcp.com Active code page: 65001
On Windows
fwrite
callsWriteFile
internally, in this case incorrectly. My solution was to just callWriteFile
directly: