getchar does not stop when using scanf

前端 未结 5 913
傲寒
傲寒 2020-11-27 22:38

I have a difficulty understanding getchar(). In the following program getchar works as expected:

#include 


int mai         


        
5条回答
  •  余生分开走
    2020-11-27 23:09

    after taking command input flush the stdin.

    fflush(stdin);
    

    but flushing a input stream results in undefined behavior (though Microsoft's C library defines the behaviour as an extension).

提交回复
热议问题