Unbuffered I/O using MicroSoft C 3.0
Tom Reingold
reintom at rocky2.UUCP
Tue Jan 13 04:27:46 AEST 1987
In article <1867 at sunybcs.UUCP>, ugwayne at 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 <stdio.h>
#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 at rockefeller.arpa BITNET: REINTOM at ROCKVAX
UUCP: {seismo|ihnp4|yale|harvard|philabs|phri}!cmcl2!rna!rocky2!reintom
More information about the Comp.lang.c
mailing list