Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!seismo!brl-adm!adm!Slomcenski.WBST@Xerox.COM From: Slomcenski.WBST@Xerox.COM Newsgroups: comp.lang.pascal Subject: Re: TURBO Pascal READ Message-ID: <7083@brl-adm.ARPA> Date: Fri, 24-Apr-87 08:40:23 EST Article-I.D.: brl-adm.7083 Posted: Fri Apr 24 08:40:23 1987 Date-Received: Sat, 25-Apr-87 09:06:16 EST Sender: news@brl-adm.ARPA Lines: 47 > > I noticed similar behavior and wrote about it to info-ibmpc >last summer. MS-DOS screws up buffering input into pascal >programs (turbo-pascal) at least. I wrote a simple program > >program test(input,output); > >var ch:char; > >begin >writeln('enter character'); >read(ch); >writeln(ch); >end. > >If you compile and run this with Turbo (com option) >and respond with a string say "abc", then the >program will run correctly the first time, echoing an a. The second time >you run it it will ignore you're input, whatever that may be and >echo a 'b'. This will go on until the string 'abc' including cr and lf >are consumed. I should back off a little. I havent tried it >since last summer and turbo and/or MS-DOS might have been fixed >since then but it drove me nuts then. The moral of this story In fact TURBO and/or MS-DOS aren't broke in this case! I believe that what you are seeing is the fact that MS-DOS "remembers" up to 16 characters typed at the keyboard in its internal type-ahead buffer. To guarantee that one and only one char is read by the program, the internal type-ahead buffer should be flushed by either an MS-DOS call (facilities to flush any remaining keys is provided by MS-DOS), or by TURBO code like: while keypressed do read(ch); The following should do what you expect it to: program test(input,output); var ch:char; begin while keypressed do read(ch); (* flush any old chars in kbd buffer *) writeln('enter character'); read(ch); writeln(ch); end. ~Bob