delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/28/07:12:46

Date: Sun, 28 Mar 1999 14:10:17 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Jorge Pacios =?iso-8859-1?Q?Mart=EDnez?= <jpacios AT gmv DOT es>
cc: djgpp AT delorie DOT com
Subject: Re: Tcl/Tk and C interaction problem
In-Reply-To: <36F12924.A1AD5AA6@gmv.es>
Message-ID: <Pine.SUN.3.91.990328140958.22925K-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019