Mail Archives: djgpp/1999/03/28/07:12:46
On Thu, 18 Mar 1999, Jorge Pacios =?iso-8859-1?Q?Mart=EDnez?= wrote:
> void readcommand (char *str) {
> char ch;
> int i = 0;
>
> read(0, &ch, 1);
> while (ch!='\n') {
> str[i] = ch;
> i++;
> read(0, &ch, 1);
> }
> str[i] = '\0';
> }
If you expect this function to read one character at a time, you need
to switch stdin to raw binary mode, like this:
setmode (0, O_BINARY);
The problem is that DOS by default uses the so-called ``cooked mode''
when reading devices, and in that mode, `read' only returns after a
newline is seen. `setmode' switches stdin into ``raw mode'' mode
where you can actually read one character at a time.
Note that switching stdin into raw mode also disables SIGINT
generation by Ctrl-C; see the docs of the `signal' function for more
details.
- Raw text -