fflush() is not working in Linux

前端 未结 9 829
后悔当初
后悔当初 2020-12-08 05:43

I used the fflush() in Linux GCC but it did not work. Are there any alternatives for that function? Here is my code:

#include
void main()
{
           


        
9条回答
  •  臣服心动
    2020-12-08 06:19

    fflush() doesn't do much for input streams but since scanf() never returns this doesn't matter. scanf() blocks because the terminal window doesn't send anything to the C program until you press Enter

    You have two options:

    1. Type 10 Enter
    2. Put the terminal into raw mode.

    The second option has many drawbacls like you will lose editing capabilities, so I suggest to read the input line by line.

提交回复
热议问题