Replacement of fflush(stdin)

后端 未结 3 555
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 22:19

I have the below code,

fflush(stdin);
print(\"Enter y/n\");
scanf(\"%c\",&a);

Here,it is quitting before giving the input.it looks like

3条回答
  •  被撕碎了的回忆
    2020-11-27 22:24

    For C on GNU

    you can use

    __fpurge(stdin);
    

    include stdio_ext.h header for accessing the function. Though the post is very old still I thought this might help some linux developers.

提交回复
热议问题