### Question 12.17

When I read numbers from the keyboard with `scanf` `"%d\n"`, it seems to hang until I type one extra line of input.

Perhaps surprisingly, `\n` in a `scanf` format string does not mean to expect a newline, but rather to read and discard characters as long as each is a whitespace character. See also question 12.20.

References: K&R2 Sec. B1.3 pp. 245-6
ANSI Sec. 4.9.6.2
ISO Sec. 7.9.6.2
H&S Sec. 15.8 pp. 357-64

Read sequentially: prev next up top

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