Program is skipping fgets without allowing input

前端 未结 2 1619
庸人自扰
庸人自扰 2021-01-22 05:15

Basically as the title says.. When my program is run from the console, it\'ll ask if you\'d like to encrypt or decrypt.. and when I input e or E, it creates a new blank line (un

2条回答
  •  醉话见心
    2021-01-22 05:42

    From http://www.cplusplus.com/reference/cstdio/fgets/

    "Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first."

    Presumably you press Enter after typing E or D. Your scanf() doesn't consume the newline so it remains in the input stream. fgets() sees the newline and returns.

提交回复
热议问题