Quote:
Originally Posted by kiddo View Post
What is the use of fflush(stdin)?
can you explain for me?
i don't really know about it,
but I often seen it after the end of a loop.....

nice....
Quote:
Originally Posted by shabbir View Post
Flushes the input buffer
It's a bad practice to use fflush(stdin) to flush the input stream.This method is UNPORTABLE, and hence should be avoided !
It will compile fine, but it's behavior is undefined on many C compilers.
But, it can be used safely with output stream.

To flush input stream, we can define something like :
Code: C
void my_fflush(FILE *pFile)
{
      char c;
      while( ((c = fgetc(pFile)) != EOF) && (c != '\n') );
}

and call it like :
Code: C
my_fflush(stdin);