By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,143 Members | 709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,143 IT Pros & Developers. It's quick & easy.

What does fflush(stdin) do?

P: 8
what is the use of fflush(stdin) in c programing.

Jun 7 '10 #1
Share this Question
Share on Google+
2 Replies

P: 13
. This function is used to flush any data in output stream. So this will compile but its behavior is undefined by the ANSI C standard. The fflush() function is only meant to be used on streams open for output, not input. Both fflush(stdin) and fflush(NULL), in some C libraries, will flush stdout and stderr, but this is completely unportable! Thus, it should not be used.
Jun 7 '10 #2

Expert Mod 5K+
P: 8,968
As mayankarpit says fflush is defined by the standard to work on output streams. If called on an input stream or a bi-directional stream thats last operation was input the behaviour is undefined.

So compiler/platforms support fflush(stdin) as an extension but using it makes the code non-portable and getting into the habit of using it could result in your getting unusual problems if you switch to a platform for which the operation is truly undefined.

There is lots of information about this on the web so do a search and it will throw up plenty of useful links like this.
Jun 7 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.