Date: Tue, 18 Feb 1997 12:16:14 +0200 (IST) From: Eli Zaretskii To: Stephen Lyda cc: djgpp AT delorie DOT com Subject: Re: IO Buffering In-Reply-To: <33086AA3.51E6@xactinc.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 17 Feb 1997, Stephen Lyda wrote: > Basically, I am trying to cause getchar() to work correctly, returning > after a single key is pressed, and not waiting until the buffer is > full or a CR is encountered. You need to switch stdin to raw mode as well as make it unbuffered. Only raw (as opposed to cooked) input from the console device is done by single characters. In cooked mode DOS itself won't return to the caller until it sees a CR; there's nothing DJGPP can do about this DOS feature. The simplest way to switch stdin to raw mode is to switch it to binary (in DJGPP, this also calls the appropriate IOCTL subfunction to put console into raw mode). Here's an example program that works for me: #include #include #include #include int main (void) { int c; setvbuf (stdin, 0, _IONBF, 0); setmode (fileno (stdin), O_BINARY); __djgpp_set_ctrl_c (1); while ((c = getchar ()) != ' ') putch (c); return 0; } This will read characters one by one and echo them until you press SPACE. The call to `__djgpp_set_ctrl_c' (look it up in the libc reference docs) is to make the program interruptible when you press Ctrl-C; this might or might not be appropriate for the application you have in mind. For example, if you need to get Ctrl-C as a normal character, you should NOT call that function (use Ctrl-Break instead to cause a SIGINT).