I want to know how to check if my input buffer (perhaps its called stdin
) is empty or not.
I dont want the program to stop if the buffer is empty, and I dont want the input to necessarily end with \n
, therefore just using scanf
is not enough.
I tried searching on google and on this website but no answer was enough.
I tried using feof(stdin)
like this:
int main()
{
char c,x;
int num;
scanf("%c",&c);
scanf("%c",&x);
num=feof(stdin);
printf("%d",num);
}
but all it did was printing 0 no matter the input. adding fflush(stdin)
after the second scanf gave the same result.
other answers suggested using select and poll but I couldnt find any explanations for those functions.
Some other forum told me to use getchar()
but I think they misunderstood my question.
if you suggest I use select/poll, could you please add an explanation about how to use those?