1

I searched the web for this, but can't find satisfactory result.

Can anyone show me the use of fflush(stdout) in C and a simple code that can be run with and without fflush(stdout) so that it is easy to figure out the difference in the output. Also please explain the same in simplest form.

  • You searched web, but did not include SO itself? – Sourav Ghosh Jan 08 '21 at 05:05
  • I asked for a simple code with and without `fflush(stdout)` as in the case of `stdin`. So that it's easy to figure out the difference in the execution. If you know a simple code then please post it here or in the comments. – Neeraj-Kumar-Coder Jan 08 '21 at 05:10
  • Please read the linked dupes, they should be able to answer your questions. – Sourav Ghosh Jan 08 '21 at 05:11
  • The two links you posted doesn't cleared my doubt. The second link is about the rules of automatic `stdout` but I asked for the use of `fflush` and the first question which is having a verified answer doesn't run the same as described on my system i.e. the expected output is the real output not the one mentioned. Please brother if you know then post just a simple program which can describe its use. I had wasted a lot of time in understanding this but being a novice it's difficult. Although I understood the concept of `fflush(stdin)` but `stdout` is tough. – Neeraj-Kumar-Coder Jan 08 '21 at 05:24
  • FYI, `fflush(stdin)` is undefined behavior, don't do that. – Sourav Ghosh Jan 08 '21 at 05:31
  • @Neeraj-Kumar-Coder _... doesn't run the same as described on my system_... see why (different stream buffering): http://crasseux.com/books/ctutorial/Stream-buffering.html – David Ranieri Jan 08 '21 at 05:31
  • 1
    and I think this answer [Why would I need use fflush on stdout before writing to stderr?](https://stackoverflow.com/a/42660873) exactly shows the case with and without the call. – Sourav Ghosh Jan 08 '21 at 05:32

0 Answers0