Hi Guys,
I wasn't expecting so many replys on this one:
I will post my question again to focus on my problem.
I am looking for an efficient way to flush stdin (IN C) to avoid the following known problem:
Code:
scanf("%d",&num);
fgets(buf,80,stdin);
scanf() will take the number and leave newline in the stream so fgets() will not wait for the user input.
"The function fflush forces a write of all user-space buffered data for the given OUTPUT or update stream via the stream's underlying write function. The open status of the stream is unaffected. If the stream argument is NULL, fflush flushes all open output streams."
The behaviour of fflush() for stdin is undefined! and should not be used for input.
So this one is not an option.