www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - stdin read returning wrong data

reply "Vathix" <vathixSpamFix dprogramming.com> writes:
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 25 2004
parent Ben Hinkle <bhinkle4 juno.com> writes:
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.
May 25 2004