简体   繁体   中英

C: While loop skips the first "scanf" on second iteration

It's because you mix reading strings and numbers.

From the first scanf(), there's left a \n (return) from the user's previous answer.

He typed something+\n, and something gets consumed but not the \n.

The second scanf() reads until \n. This is, it reads nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM