Jump to content

what fflush(stdin) doing in c?

is this a directory you are talking about

Please follow your topics guys, it's very important! CoC F.A.Q  Please use the corresponding PC part picker link for your country USA, UK, Canada, AustraliaSpain, Italy, New Zealand and Germany

also if you find anyone with this handle in games its most likely me so say hi

 

Link to post
Share on other sites

10 seconds in google

https://www.google.co.uk/webhp?sourceid=chrome-instant&rlz=1C1CHFX_enGB521GB521&ion=1&espv=2&ie=UTF-8#q=fflush%20stdin

 

http://stackoverflow.com/questions/18170410/what-is-the-use-of-fflushstdin-in-c-programming

 

 

It's not in standard C, so the behavior is undefined.

Some implementation uses it to clear stdin buffer.

From C11 7.21.5.2 The fflush function, fflush works only with output/update stream, not input stream.

If stream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behavior is undefined.

Link to post
Share on other sites

fflush(stdin) clears the input buffer.

It's not recommended to always use it, cuz you might clear something you find valuable in your program.

You should use it (for example) when you are inputting a string while being on a loop. So you clear your buffer every loop before typing the string. That's just an example tho.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×