Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!cmcl2!yale!husc6!wjh12!maynard!campbell From: campbell@maynard.BSW.COM (Larry Campbell) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: Unbuffered I/O using MicroSoft C 3.0 Message-ID: <802@maynard.BSW.COM> Date: Tue, 13-Jan-87 22:57:57 EST Article-I.D.: maynard.802 Posted: Tue Jan 13 22:57:57 1987 Date-Received: Wed, 14-Jan-87 23:17:11 EST References: <1867@sunybcs.UUCP> Reply-To: campbell@maynard.UUCP (Larry Campbell) Followup-To: comp.sys.ibm.pc Organization: The Boston Software Works, Inc. Lines: 25 Keywords: ioctl Summary: use ioctl to put console in binary mode Xref: mnetor comp.lang.c:688 comp.sys.ibm.pc:974 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@maynard.uucp 120 Fulton Street, Boston MA 02109 uucp: {alliant,wjh12}!maynard!campbell +1 617 367 6846 ARPA: campbell%maynard.uucp@harvisr.harvard.edu MCI: LCAMPBELL