I read into C11 standard this:
Input white-space characters (as speci?ed by the isspace function) are
skipped, unless the speci?cation includes a [, c, or n speci?er.
so I understand that if I use that specifiers the next scanf
can contains for example a new line.
But if I write this:
char buff[5 + 1];
printf("Input: ");
scanf("%10s", buff);
printf("Input: ");
char buff_2[5 + 1];
scanf("%[abcde]", buff_2);
and then I input, i.e., RR
and then Return,
the next scanf
fails because of
.
So also %s
doesn't discard a new line?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…