I’m having trouble creating files in UTF-8 for appending. The MSDN documentation states that using “a+” for the mode parameter opens files for “reading and appending”, which is what I need to do. For some reason, when no file exists and I’m creating a new one on the fly, the BOM or byte order mark that’s created in the new file is malformed.
Basically, it is only writing the first 2 of 3 bytes. It’s supposed to write the bytes 0xEF, 0xBB, and 0xBF, but it’s only writing the first two (0xEF and 0xBB). If you look at it in a text editor, it should look like this: , but looks like this instead: ï». Has anyone seen this? A known fopen bug maybe? This is the code that I’m using to open, and I’m using a simple fwrite to write the file. Everything works fine when I pass in “w” (write) for the mode, but the BOM is malformed for “a” or “a+”:
_tfopen(PathToFile,UNICODE_CHAR_MACRO("a+, ccs=UTF-8"));
I finally figured this out. The third party software that we’re using was actually stripping off the last byte of the BOM, thinking that it was the ctrl-z MS-DOS end of file character.