Cannot figure out how to use getchar(); in C

前端 未结 4 659
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 22:52
#include 
int main(void)

{
    char F,C;

    printf(\"Do you have a Fever? y/n\\n\");
    F = getchar();

    printf(\"Do you have a runny nose or c         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 23:36

    When you enter a character ,it is stored in F,then when you press enter,it is stored in stdin buffer and when next getchar() comes it reads it's input from the stdin buffer ,for this use fflush(stdin) before every getchar() you use.

提交回复
热议问题