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

Use a while loop after each getchar() if you want to process only one character

printf("Do you have a Fever? y/n\n");
F = getchar();
while((F = getchar()) != EOF && F != '\n') // This will eat up all other characters
    ;

printf("Do you have a runny nose or cough? y/n\n");
C = getchar();
while((C = getchar()) != EOF && C != '\n')
    ;

Leave a Comment