What does fflush(stdin) do?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santechselva
    New Member
    • May 2010
    • 8

    What does fflush(stdin) do?

    hi,
    what is the use of fflush(stdin) in c programing.


    regards,
    santosh
  • mayankarpit
    New Member
    • Jun 2010
    • 13

    #2
    . 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.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      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.

      Comment

      Working...