Sams Teach Yourself C in 21 Days

(singke) #1
If your DOS system has a printer connected to port LPT1:, you can compile and run this
program. It prints three lines on the page. Line 14 sends an “\f”to the printer. \fis the
escape sequence for a form feed, the command that causes the printer to advance a page
(or, in the case of a laser printer, to eject the current page).

372 Day 14

This output is printed by the printer. It won’t appear on-screen.
Note

DOusefprintf()to create programs
that can send output to stdout,stderr,
stdprn, or any other stream.
DOusefprintf()withstderrto print
error messages to the screen.
DOcreate functions such as
error_messageto make your code more
structured and maintainable.

DON’Tever try to redirect stderr.
DON’Tusestderrfor purposes other
than printing error messages or warn-
ings.

DO DON’T


Summary ............................................................................................................


This was a long day full of important information on program input and output. You
learned how C uses streams, treating all input and output as a sequence of bytes. You also
learned that ASNI C has three predefined streams:
stdin The keyboard
stdout The screen
stderr The screen

Input from the keyboard arrives from the stream stdin. Using C’s standard library func-
tions, you can accept keyboard input character by character, a line at a time, or as for-
matted numbers and strings. Character input can be buffered or unbuffered, echoed or
unechoed.
Output to the display screen is normally done with the stdoutstream. Like input, pro-
gram output can be by character, by line, or as formatted numbers and strings. For output
to the printer, you use fprintf()to send data to the stream stdprn.

22 448201x-CH14 8/13/02 11:12 AM Page 372

Free download pdf