It's number of characters, not bytes, and it includes the termination - I'm
inclined to declare like this:

wchar_t buff[128]={0};

So if it fails, you have zeros in it, instead of what was left in the stack
...


On Sun, Dec 6, 2020, 11:27 Greg Keogh <gfke...@gmail.com> wrote:

>
> Did you look at the iconv API?
>>
>
> I didn't know about that, but I was hoping to avoid things like it. After
> another hour of stuffing around and reading the fine print of the old C
> library functions
> <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-s-wfopen-s?view=msvc-160>
> I found this works:
>
> FILE* file;
> _wfopen_s(&file, L"K:\\temp\\temp-utf8.txt", L"r, ccs=UTF-8")
> wchar_t buff[128];
> fgetws(buff, 128, file)
> wprintf_s(buff);
>
> No wonder I missed that subtle parameter change. The file's BOM is
> silently consumed and I just get back wide strings terminated by \n\0.
> Here's a copy of a watch value of a line:
>
> 0x00d3fadc L"Greek = ΑΒΓΔ\n"
>
> *Greg K*
>
> P.S. I'm still not sure that the 128 length in the code is correct. Is it
> 128 wide or 256 bytes? (what a mess)
>
> P.P.S. I can't figure out how to display Unicode characters on the DOS
> console. I tried chcp 65001 and changing to different TT fonts, but nothing
> works.
>

Reply via email to