Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!cmcl2!rna!rocky2!reintom From: reintom@rocky2.UUCP (Tom Reingold) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: Unbuffered I/O using MicroSoft C 3.0 Message-ID: <310@rocky2.UUCP> Date: Mon, 12-Jan-87 13:27:46 EST Article-I.D.: rocky2.310 Posted: Mon Jan 12 13:27:46 1987 Date-Received: Tue, 13-Jan-87 06:46:22 EST References: <1867@sunybcs.UUCP> Organization: Rockefeller Univ.,N.Y.C 10021 Lines: 68 Summary: Here is one solution to your problem --- Xref: mnetor comp.lang.c:672 comp.sys.ibm.pc:943 In article <1867@sunybcs.UUCP>, ugwayne@sunybcs (Wayne Nelligan) writes: > > A friend of mine recently asked me "If I knew of a program that would let > your printer act like a typewriter?". Since a program of this sort seemed > really easy to write (just get characters and send them to the printer), I > decided I would just write one myself. Well, I am sorry to say, things have > not been as easy as I thought they would be. The problem is that I can't get > the printer to just print one character at a time. It only prints out a line > at a time. > [...] > So what I would like to know then, Is how would I get a program like > this to work? How do you get unbuffered I/O using MicroSoft C 3.0? > What am I doing wrong? If anyone has any suggestions, I > would sure appreciate a response. This is really driving me crazy. > > Thanks in advance, > Wayne You are probably automatically generating unbuffered output but the printer buffers its input until a line is full. A line is full either when it gets a CR or when its length is reached. You can fool it with the method outlined in the enclosed program. Good luck. Tom ======================================================================== #include#define CR '\r' #define LF '\n' #define TAB '\t' #define SPACE ' ' /* * This is an example program. It reads the standard input * and prints it to the standard printer, one character * at a time. Tabs and other subtle things will not work * because it is an example to show you that you can do * what you want to. * * The printer prints when the line length is reached or * when it gets a RETURN character. This program sends one * after each character. * */ main() { char line[256]; int i, j; while ((gets(line)) != NULL) { for (i=0; i < strlen(line); i++) { fputc(line[i], stdprn); fputc(CR, stdprn); fputc(SPACE, stdprn); for (j=0; j < i; j++) fputc(SPACE, stdprn); } fputc(LF, stdprn); } } -- Tom Reingold; The Rockefeller University; 1230 York Av; NY 10021 PHONE: (212) 570-7709 [office]; (212) 304-2504 [home] ARPANET: reintom@rockefeller.arpa BITNET: REINTOM@ROCKVAX UUCP: {seismo|ihnp4|yale|harvard|philabs|phri}!cmcl2!rna!rocky2!reintom