Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

why do we use fflush(stdin) in c programming?

OpenStudy (rsmith6559):

Unless specifically programmed, the OS will actually do I/O at it's convenience. This results in much better performance. One of the most common techniques is read ahead and write behind. The basic idea is that when a file is opened and part of it read, the OS will read farther ahead and cache it in memory because another read request will probably follow, and instead of going out to a peripheral, the request can be answered from memory. Write behind involves caching write requests in memory, usually for a maximum of 5 seconds, until the write can be scheduled efficiently. If another write request for that file comes in, it can be appended to the orginal. fflush() (File Flush) flushes out any remnants from the file's cache, so you can be sure that it's empty. It's usually not used on stdin, it's used to flush an output cache to (usually) disk.

OpenStudy (e.mccormick):

The correct answer is never. It is undefined for stdin and can cause different results depending on the compiler.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!