0

My Windows application calls a system command using _wpopen. This command produces a UTF8 response that I attempt to read using fgetws into a buffer of wchar_t. The problem is that the result in my buffer is not correct. There might be a problem with character widths as my buffer contains 12 characters where in UTF8 it should contain only 4. I use Microsoft Visual Studio 2010.

I have independently verified that the system command produces proper output. Thus, it is somehow the reading operation that messes up the encoding. What to do? Thank you!

1 Answers1

0

The fgetws function expects the input to be either MBCS or UTF-16 depending on whether you open the file in text or binary mode. It does not process UTF-8.

Instead, use fgets and then explicitly convert from UTF-8 to whatever encoding you're wanting to use.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158