* better
[mascara-docs.git] / lang / C / the.ansi.c.programming.language / notes.accompany.ansi.c / sx10a.html
blobb255fc4256c894d7377a78dd3a7e07b7a8ec9306
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. -->
5 <html>
6 <head>
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>
13 </head>
14 <body>
15 <H2>section 7.1: Standard Input and Output</H2>
17 <p>Note that ``a text stream'' might refer
18 to input
19 (to the program)
20 from the keyboard or output to the screen,
21 <em>or</em>
22 input and output from files on disk.
23 (For that matter,
24 it can also refer to input and output from other peripheral devices,
25 or the network.)
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,
34 and when writing,
35 writing a <TT>'\n'</TT> causes
36 the underlying system's actual end-of-line representation to be written.)
37 </p><p>pages 152-153
38 </p><p>The ``<TT>lower</TT>'' program is an example of a <dfn>filter</dfn>:
39 it reads its standard input,
40 ``filters''
41 (that is, processes)
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
46 or the
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 &lt; inputfile
53 </pre>and perhaps the output:
54 <pre> lower &lt; inputfile &gt; outputfile
55 </pre>(notice that spaces may precede and follow
56 the <TT>&lt;</TT> and <TT>&gt;</TT> characters).
57 Or, a filter program like <TT>lower</TT> might appear in a longer
58 pipeline:
59 <pre> oneprogram | lower | anotherprogram
61 anotherprogram &lt; inputfile | lower | thirdprogram &gt; outputfile
62 </pre>Filters like these are not terribly useful,
63 though,
64 under a Graphical User Interface
65 such as the Macintosh or Microsoft Windows.
66 </p><hr>
67 <p>
68 Read sequentially:
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>
73 </p>
74 <p>
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>
78 </p>
79 </body>
80 </html>