write unicode to a file

hi everybody, i have some problem with writing an array of type wchar_t to a file.
here is my code

1
2
3
4
5
6
7
8
9
10
11
...

wchar_t name[] = "акмал";

FILE * pFile;
pFile = fopen ("myfile.txt","w");
	
fwrite(name, sizeof(wchar_t), wclen(name), pFile);
fclose(pFile);

...


the output file consist a strange symbols,
where is problem, please help.

You're not writing the byte order mark. The editor is probably assuming that the file has an endianness different than your CPU (e.g. your CPU is an x86 and the editor is trying to read the file as a big endian).

I'm not sure what The Standard says about using Unicode character inside source files. Your compiler may be building the array correctly or not. I'm not sure.
A couple of observations.

wchar_t name[] = "акмал";
should be
wchar_t name[] = L"акмал";
It should have failed to compile.

As you'll never encounter '\n', you should open the file in binary mode.
FILE *pFile = fopen("myfile.txt","bw");
Topic archived. No new replies allowed.