0

I started programming and I learned about the command that is fflush(stdout);. I understand why I need it for most platforms, but I'm still asking myself some questions...

1.Isn't \n supposed to buffer on msys2 because it's line buffered? (Mintty)

2.Why do I need to use it on Eclipse while I don't need to use it on Clion?

3.Am I the only one struggling with that problem ESPECIALLY on Eclipse and Msys2?

Edit : 3.1. I'm asking because I don't need fflush(stdout); on my school's Windows computers. Why is that?

Lundin
  • 195,001
  • 40
  • 254
  • 396
Ender
  • 1
  • 2
  • actually it doesn't change anything if my printf outputs end with \n or not. It just doesn't show on the screen. But even if I don't put \n in Clion, it still shows me the output in the IDE's terminal. – Ender Oct 25 '16 at 04:43
  • 3
    Welcome to the wonderful world of IDEs. I've not yet found a nice IDE to use on a Mac — but I'm an antique and haven't found a nice IDE to use anywhere else either. There are problems with the way Eclipse handles 'terminal I/O' for C programs. There was a question on this topic in the last month or two; finding it will be the pain. (And Windows does things differently because it is Windows.) – Jonathan Leffler Oct 25 '16 at 04:46
  • I've heard that Xcode is great for Mac. But I'm on Windows so yeaaaah... (I'M DIFFERENT!) – Ender Oct 25 '16 at 04:50
  • 1
    I've seen many beginners lately writing output with *leading* newlines. That will flush the previous output not the current. You don't do that? You put the newlines (`"\n"`) at the end? – Some programmer dude Oct 25 '16 at 05:28
  • Depends on what `stdout` is pointing at. It is normally inherited from its parent process, and that could be anything, including a file (think of `> out` redirection). Some terminal systems are line buffered, some are not. – cdarke Oct 25 '16 at 05:34

1 Answers1

-2

[This answer is talking about fflush(stdin) and is not really an answer.
fflush(stdout) does not have undefined behaviour.]

fflush is used to clear the stdout buffer and it has undefined behaviour. Sometimes, fflush won't work and it is better to use fpurge instead.

For more information to your question about the behaviour on Windows, refer to this thread - How come fflush(stdin) function is not working?

Swordfish
  • 12,971
  • 3
  • 21
  • 43
Vishal B U
  • 17
  • 1
  • 1
  • 5