Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to a file in Unicode

Tags:

c

unicode

I am having some problems writing to a file in unicode inside my c program. I am trying to write a unicode Japanese string to a file. When I go to check the file though it is empty. If I try a non-unicode string it works just fine. What am I doing wrong?

setlocale(LC_CTYPE, "");
FILE* f;
f = _wfopen(COMMON_FILE_PATH,L"w");
fwprintf(f,L"日本語");
fclose(f);

Oh about my system: I am running Windows. And my IDE is Visual Studio 2008.

like image 277
Lefteris Avatar asked Mar 11 '10 17:03

Lefteris


People also ask

Do TXT files support Unicode?

txt (also NamesList. lst) is a plain text file used to drive the layout of the character code charts in the Unicode Standard.


1 Answers

You might need to add the encoding to the mode. Possibly this:

f = _wfopen(COMMON_FILE_PATH,L"w, ccs=UTF-16LE");
like image 65
Mark Wilkins Avatar answered Sep 28 '22 05:09

Mark Wilkins