1 <!DOCTYPE HTML PUBLIC
"-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995, 1996 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
7 <link rev=
"owner" href=
"mailto:scs@eskimo.com">
8 <link rev=
"made" href=
"mailto:scs@eskimo.com">
9 <title>section
7.1: Standard Input and Output
</title>
10 <link href=
"sx10.html" rev=precedes
>
11 <link href=
"sx10b.html" rel=precedes
>
12 <link href=
"sx10.html" rev=subdocument
>
15 <H2>section
7.1: Standard Input and Output
</H2>
17 <p>Note that ``a text stream'' might refer
20 from the keyboard or output to the screen,
22 input and output from files on disk.
24 it can also refer to input and output from other peripheral devices,
26 </p><p>Note that the stdio library generally does newline translation for you.
27 If you know that lines are terminated by a linefeed on Unix
28 and a carriage return on the Macintosh and a
29 carriage-return/linefeed combination on MS-DOS, you don't have
30 to worry about these things in C, because the line termination
31 will always appear to a C program to be a single
<TT>'\n'
</TT>.
32 (That is, when reading,
33 a single
<TT>'\n'
</TT> represents the end of the line being read,
35 writing a
<TT>'\n'
</TT> causes
36 the underlying system's actual end-of-line representation to be written.)
38 </p><p>The ``
<TT>lower
</TT>'' program is an example of a
<dfn>filter
</dfn>:
39 it reads its standard input,
42 it in some way, and writes the result to its standard output.
43 Filters are designed for
44 (and are only really useful under)
45 a command-line interface such as the Unix shells
47 MS-DOS command.com interface.
48 Obviously, you would rarely invoke a program like
<TT>lower
</TT>
49 by itself, because you would have to type the input text at it
50 and you could only see the output ephemerally on your screen.
51 To do any real work, you would always redirect the input:
52 <pre> lower
< inputfile
53 </pre>and perhaps the output:
54 <pre> lower
< inputfile
> outputfile
55 </pre>(notice that spaces may precede and follow
56 the
<TT><</TT> and
<TT>></TT> characters).
57 Or, a filter program like
<TT>lower
</TT> might appear in a longer
59 <pre> oneprogram | lower | anotherprogram
61 anotherprogram
< inputfile | lower | thirdprogram
> outputfile
62 </pre>Filters like these are not terribly useful,
64 under a Graphical User Interface
65 such as the Macintosh or Microsoft Windows.
69 <a href=
"sx10.html" rev=precedes
>prev
</a>
70 <a href=
"sx10b.html" rel=precedes
>next
</a>
71 <a href=
"sx10.html" rev=subdocument
>up
</a>
72 <a href=
"top.html">top
</a>
75 This page by
<a href=
"http://www.eskimo.com/~scs/">Steve Summit
</a>
76 //
<a href=
"copyright.html">Copyright
</a> 1995,
1996
77 //
<a href=
"mailto:scs@eskimo.com">mail feedback
</a>