🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #15743

Re: Unbuffered I/O using MicroSoft C 3.0

#15743
From: Clayton Cramer
Date: Fri, 16 Jan 1987 02:04
35 lines
1970 bytes
> 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.

Even easier:

#include <fcntl.h>
	setmode (fileno (stdin), O_BINARY);

/* You are now in binary mode on stdin. */

	setmode (fileno (stdin), O_TEXT);
        
/* You are back in text mode on stdin. */

Clayton E. Cramer
Technical Details
Message-ID: <1299@kontron.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!husc6!panda!genrad!decvax!decwrl!pyramid!voder!kontron!cramer
References: <1867@sunybcs.UUCP> <802@maynard.BSW.COM>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!husc6!panda!genrad!decvax!decwrl!pyramid!voder!kontron!cramer
From: cramer@kontron.UUCP (Clayton Cramer)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Unbuffered I/O using MicroSoft C 3.0
Message-ID: <1299@kontron.UUCP>
Date: Thu, 15-Jan-87 21:04:02 EST
Article-I.D.: kontron.1299
Posted: Thu Jan 15 21:04:02 1987
Date-Received: Fri, 16-Jan-87 21:37:55 EST
References: <1867@sunybcs.UUCP> <802@maynard.BSW.COM>
Organization: Kontron Electronics, Mt. View, CA
Lines: 35