Unbuffered I/O using MicroSoft C 3.0

Tom Reingold reintom at rocky2.UUCP
Tue Jan 13 05:22:54 AEST 1987


[]

Ok, this program more closely addresses the problem you describe.
As you can see, this small problem has been fun for me.

=================================================================
#include <stdio.h>

#define   CR      '\r'
#define   LF      '\n'
#define   SPACE   ' '
#define   ESC     '\033'

/* 
 * This is an example program.  It directly reads the keyboard
 * and prints 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.
 *
 * This program exits after the user presses ESCAPE.
 *
 */

main()
{
    int i, linelen, c;

    linelen = 0;
    while ((c=getche()) != ESC) {
        fputc(c, stdprn);
        if (c != CR) {
            linelen++;
            fputc(CR, stdprn);
            for (i = 0; i < linelen; i++)
                fputc(SPACE, stdprn);
            fflush(stdprn);
        }
        else {
            linelen = 0;
            putchar(LF);
            fputc(LF, stdprn);
            fflush(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