Calling scanf() after another string input function creates phantom input

前端 未结 3 808
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 11:00

Here\'s a small program:

#include 

int main() {
  char str[21], choice[21]; int size;
  while(1){
    printf(\"$ \");
    fgets(str, 20, stdin);
         


        
3条回答
  •  粉色の甜心
    2021-01-25 11:34

    Use a 'char' of a specific size char choice [1]

    OR

    char c[1];
    c = getchar();
    if(c[0] == 'y' || c[1] == 'y'){
     // DO SOMETHING
    }
    

提交回复
热议问题