Unbuffered I/O using MicroSoft C 3.0

Larry Campbell campbell at maynard.BSW.COM
Wed Jan 14 13:57:57 AEST 1987


Summary: Can't read a character at a time using Microsoft C;  program
	 sees no input until carriage return typed.

	 A respondent erroneously blamed the printer on which the C program
	 was echoing its output;  the respondent failed to note that the
	 original poster had thought of that and had tried sending output
	 to the console, with identical results.

This problem has nothing to do with Microsoft C.  It is a feature of DOS.
Standard input (the console) is normally opened by DOS in ASCII mode, in
which a program reading from stdin blocks until a carriage return is typed.

To be woken up on every character, you need to put stdin into binary mode.
You do this with the IOCTL DOS call (INT 21, AH=44).  Do subfunction AL=0
first to get the mode bits (returned in DX), then set the "binary" bit
(bit 5), then do subfunction 1 to set the mode bits (from DX).  For both
calls, the file handle goes in BX.

Note that binary mode will also disable ^S and ^C processing.  Don't forget
to put the console back in ASCII mode!
-- 
Larry Campbell                                The Boston Software Works, Inc.
Internet: campbell at maynard.uucp             120 Fulton Street, Boston MA 02109
uucp: {alliant,wjh12}!maynard!campbell              +1 617 367 6846
ARPA: campbell%maynard.uucp at harvisr.harvard.edu      MCI: LCAMPBELL



More information about the Comp.lang.c mailing list