Why is adding a leading space in a scanf format string recommended?

前端 未结 2 380
别那么骄傲
别那么骄傲 2020-12-06 07:38

I am currently reading this book \"C11 Programming for beginners\" and in the scanf() chapter it says:

\"Always add a leading space before the first control string c

2条回答
  •  既然无缘
    2020-12-06 08:17

    "Always add a leading space before the first control string character to ensure accurate character input."

    This is to consume any trailing character in the stdin that might have been left by previous user input (like the carriage return), before the scanf reads the user input.

提交回复
热议问题