section 7.7: Line Input and Output

pages 164-165

To summarize, puts is like fputs except that the stream is assumed to be the standard output (stdout), and a newline ('\n') is automatically appended. gets is like fgets except that the stream is assumed to be stdin, and the newline ('\n') is deleted, and there's no way to specify the maximum line length. This last fact means that you almost never want to use gets at all: since you can't tell it how big the array it's to read into is, there's no way to guarantee that some unexpectedly-long input line won't overflow the array, with dire results. (When discussing the drawbacks of gets, it's customary to point out that the ``Internet worm,'' a program that wreaked havoc in 1988 by breaking into computers all over the net, was able to do so in part because a key network utility on many Unix systems used gets, and the worm was able to overflow the buffer in a particularly low, cunning way, with the dire result that the worm achieved superuser access to the attacked machine.)

Read sequentially: prev next up top

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