* remove "\r" nonsense
[mascara-docs.git] / C / the.ansi.c.programming.language / notes.accompany.ansi.c / sx10g.html
blobff297daa2cc2000f590100e790ec033a88442cb3
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.7: Line Input and Output</title>
10 <link href="sx10f.html" rev=precedes>
11 <link href="sx10h.html" rel=precedes>
12 <link href="sx10.html" rev=subdocument>
13 </head>
14 <body>
15 <H2>section 7.7: Line Input and Output</H2>
17 pages 164-165
18 <p>To summarize,
19 <TT>puts</TT> is like <TT>fputs</TT>
20 except that the stream is assumed to be the standard output (<TT>stdout</TT>),
21 <em>and</em> a newline (<TT>'\n'</TT>) is automatically appended.
22 <TT>gets</TT> is like <TT>fgets</TT>
23 except that the stream is assumed to be <TT>stdin</TT>,
24 and the newline (<TT>'\n'</TT>) is deleted,
25 <em>and</em> there's no way to specify the maximum line length.
26 This last fact means that
27 you
28 almost never
29 want
30 to use <TT>gets</TT>
31 at all:
32 since you can't tell it how big the array it's to read into is,
33 there's no way to guarantee
34 that some unexpectedly-long input line
35 won't overflow the array,
36 with dire results.
37 (When discussing the drawbacks of <TT>gets</TT>,
38 it's customary to point out that the ``Internet worm,''
39 a program that wreaked havoc in 1988
40 by breaking into computers all over the net,
41 was able to do so
42 in part
43 because a key network utility
44 on many Unix systems
45 used <TT>gets</TT>,
46 and
47 the worm was able to overflow the buffer
48 in a particularly low, cunning way,
49 with the dire result that
50 the worm achieved superuser access to the attacked machine.)
51 <br></p><hr>
52 <p>
53 Read sequentially:
54 <a href="sx10f.html" rev=precedes>prev</a>
55 <a href="sx10h.html" rel=precedes>next</a>
56 <a href="sx10.html" rev=subdocument>up</a>
57 <a href="top.html">top</a>
58 </p>
59 <p>
60 This page by <a href="http://www.eskimo.com/~scs/">Steve Summit</a>
61 // <a href="copyright.html">Copyright</a> 1995, 1996
62 // <a href="mailto:scs@eskimo.com">mail feedback</a>
63 </p>
64 </body>
65 </html>