Question 12.23

Why does everyone say not to use gets()?


Unlike fgets(), gets() cannot be told the size of the buffer it's to read into, so it cannot be prevented from overflowing that buffer. As a general rule, always use fgets(). See question 7.1 for a code fragment illustrating the replacement of gets() with fgets().

References: Rationale Sec. 4.9.7.2
H&S Sec. 15.7 p. 356


Read sequentially: prev next up top


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