scanf
leaves the input stream pointing to the
. In your case it doesn't make a difference: each time it's called, scanf
will move along until it finds the next non-whitespace character. So giving it 10 lines of name, a, b
as input will work as you expect.
But consider this:
scanf("%d", &a);
fgets(str, 20, stdin);
fgets
reads until it finds the first newline character, so str
will just get a value of
, and fgets
will not read the next line of input.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…