Reading a Binary File with UTF16 format

417 Views Asked by At

In C language, I am trying to read a Binary file in UTF16 format.

I tried to this;

binaryFile = fopen("data.dat", "rb, ccs=UTF16LE");

And it did not work. I need to do this without using the UTF16 reading library specifically, and I can't think of anything other than this solution.

Can you help me, thanks in advance.

1

There are 1 best solutions below

0
On

According to the Microsoft documentation for fopen, they support a non-standard extension to specify the text encoding, but you misspelled it. It should be:

binaryFile = fopen("data.dat", "rb, ccs=UTF-16LE");

This is a typical example of the Embrace, Extend and Extinguish strategy deployed by this company in an attempt to lock developers in their wall garden.

Making the ccs flag case sensitive and using dashes are regrettable design choices. Lagging on UTF-8 adoption and encouraging 16-bit text file support is plaguing programmers to this day. Try your best to have the format of this file changed to UTF-8.