Re 2: reading single char from standard input

Posted by William on February 21, 2007

In Reply to Re: reading single char from standard input posted by Frank Crenshaw on February 21, 2007

: : How do i read a single char from standard input... read(c) is blocking until enter is pressed, i don't want that, i need a single char immedietly. Can i connect somehow TFileStream with standard input?

: This is a very simple console program.
: This will read and write characters to and from standard io until a carriage return is entered - then it will terminate.
:
: (code: ...)

The function Read does NOT wait until Enter is pressed. Andre probably confuses Read with ReadLn.

The following extremely simple console application works the same as the Frank's code, only a bit shorter and easier to understand :)

program Project1;
{$APPTYPE CONSOLE}

uses SysUtils;

var
  Ch: char;

begin
  repeat
    read(Ch);
  until (Ch = #13); // #13 is the ENTER code
end.

Related articles

       

Follow Ups