section 7.1: Standard Input and Output

Note that ``a text stream'' might refer to input (to the program) from the keyboard or output to the screen, or input and output from files on disk. (For that matter, it can also refer to input and output from other peripheral devices, or the network.)

Note that the stdio library generally does newline translation for you. If you know that lines are terminated by a linefeed on Unix and a carriage return on the Macintosh and a carriage-return/linefeed combination on MS-DOS, you don't have to worry about these things in C, because the line termination will always appear to a C program to be a single '\n'. (That is, when reading, a single '\n' represents the end of the line being read, and when writing, writing a '\n' causes the underlying system's actual end-of-line representation to be written.)

pages 152-153

The ``lower'' program is an example of a filter: it reads its standard input, ``filters'' (that is, processes) it in some way, and writes the result to its standard output. Filters are designed for (and are only really useful under) a command-line interface such as the Unix shells or the MS-DOS command.com interface. Obviously, you would rarely invoke a program like lower by itself, because you would have to type the input text at it and you could only see the output ephemerally on your screen. To do any real work, you would always redirect the input:

	lower < inputfile
and perhaps the output:
	lower < inputfile > outputfile
(notice that spaces may precede and follow the < and > characters). Or, a filter program like lower might appear in a longer pipeline:
	oneprogram | lower | anotherprogram
or
	anotherprogram < inputfile | lower | thirdprogram > outputfile
Filters like these are not terribly useful, though, under a Graphical User Interface such as the Macintosh or Microsoft Windows.


Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995, 1996 // mail feedback