[Issue 12990] utf8 string not read/written to windows console

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Oct 25 13:25:45 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12990

--- Comment #18 from Sum Proxy <sum.proxy at gmail.com> ---
>From what I know this program will work incorrectly for any non-ascii unicode
input, which I have confirmed through simple tests.

scanf and strlen rely on '\0' to indicate string termination, but I don't think
this goes well with unicode strings.

I believe the right way to do something similar (without buffer length) is
this:

#include <stdio.h>
#include <fcntl.h>
#include <io.h>

int main( void )
{
    wchar_t buf[1024];

    _setmode( _fileno( stdin ), _O_U16TEXT );
    _setmode( _fileno( stdout ), _O_U16TEXT );

    wscanf( L"%ls", buf );
    wprintf( L"%s", buf );

}

For further info please refer to http://www.siao2.com/2008/03/18/8306597.aspx
and http://msdn.microsoft.com/en-us/library/tw4k6df8%28v=vs.120%29.aspx

HTH,
Thanks.

--


More information about the Digitalmars-d-bugs mailing list