May 25, 2004 stdin read returning wrong data | ||||
---|---|---|---|---|
| ||||
Here's example code for Windows: import std.stream; extern(Windows) void Sleep(uint); int main() { stdout.writeLine("Type quickly but don't return:"); Sleep(3000); stdout.writeString("Press return> "); stdout.writeLine("You wrote> " ~ stdin.readLine()); return 0; } This is what happens: Type quickly but don't return: Press return> foo You wrote> too What happens is if you type while the program is busy but don't return, the first character of the read data is wrong. I tested it with C functions and it worked as expected. |
May 26, 2004 Re: stdin read returning wrong data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | On Tue, 25 May 2004 10:32:42 -0400, "Vathix" <vathixSpamFix@dprogramming.com> wrote: >Here's example code for Windows: > >import std.stream; >extern(Windows) void Sleep(uint); >int main() >{ > stdout.writeLine("Type quickly but don't return:"); > Sleep(3000); > stdout.writeString("Press return> "); > stdout.writeLine("You wrote> " ~ stdin.readLine()); > return 0; >} > > >This is what happens: > >Type quickly but don't return: >Press return> foo >You wrote> too > > >What happens is if you type while the program is busy but don't return, the first character of the read data is wrong. I tested it with C functions and it worked as expected. The bug also reproduces in version 0.86 (that was the latest one I had before 0.90) so it wasn't due to the recent std.stream changes. I notice that including std.c.stdio and using scanf gets the right answer. Since I've been poking around in std.stream lately I'll give it a shot. |
Copyright © 1999-2021 by the D Language Foundation