According to my man page, "The behavior of fgetwc() depends on the LC_CTYPE category of the cur‐
rent locale."
Try adding
+#include <locale.h>
...
+char *loc = setlocale (LC_ALL, "");
...
+printf ("locale is %s\n",loc);
I was interested in this, because I want to get to know wide characters.
After cross-compiling with the above changes, I got this:[not me]$ i686-pc-mingw32-gcc test_fgetwc.c -o t.exe
[not me]$ ./t.exe
locale is English_United States.1252
[FEFF][72][6F][77][31][ D][ A][72][6F][77][32][ D][ A]
[not me]$ hexdump -e '1/2 "[%2X]" ' w*
[FEFF][72][6F][77][31][ D][ A][72][6F][77][32][ D][ A]
[not me]$
But compiled on Linux, it can not parse the file because of the locale:
[not me]$ ./t
locale is en_US.utf8
/*NULL, nothing, nada*/
[not me]$
So I thought I would get smart and change the locale to try to read the file.
[not me]$ locale -a|grep US
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8
es_US
es_US.iso88591
es_US.utf8
yi_US
yi_US.cp1255
yi_US.utf8
I tried seting the locale manually.-char *loc = setlocale (LC_ALL, "");
+char *loc = setlocale (LC_ALL, "en_US.iso88591");
Recompile (on Linux as Linux)
[not me]$ gcc test_fgetwc.c -o t
[not me]$ ./t
locale is en_US.iso88591
[FF][FE][72][ 0][6F][ 0][77][ 0][31][ 0][ D][ 0][ A][ 0][72][ 0][6F][ 0][77][ 0][32][ 0][ D][ 0][ A][ 0]
Finally, it occurred to me that on Linux, wchar_t is 32 bits wide, so I saved it as Western (ISO-8859-15) and Linux could read it.
[not me]$ ./t
locale is en_US.iso88591
[72][6F][77][31][ D][ A][72][6F][77][32][ D][ A]