0
fflush (stdout)
i read article about fflush() recently... my question is, what is the output of fflush (stdout)?
2 odpowiedzi
0
There is an automatic fflush() of all writable streams when
the program exits on any hosted environment. (The rules are different
for Freestanding environments.) Therefor in the program above,
the fflush does not add anything.
The program given has a portability problem: the output to stdout
does not finish with a \n. Implementations are permitted to drop
any terminal partial line on text streams. The presence of the
explicit fflush() does not affect this behaviour.
Generally speaking, fflush() has two uses:
1) it releases the current contents of the output buffer to the system
for whatever processing the system has for it. This is useful if
something (or some-one) is waiting for the output. For example if the
program was producing only a few lines of output every tens of minutes,
the user probably would prefer not to wait until the buffer fills up
(8Kb buffers are common) to see what has been happening. And when you
start gettting into interprocess communictions (outside the scope of C
itself), releasing current results for processing can be crucial to
proper operation;
1b) As a subset of the above: releasing an input prompt to the user
just before expecting input can be fairly important to the user;
2) In cases where you are updating a stream (opened with 'r+' or 'rb+'
or 'a+' or 'ab+' modes), flushing written output data before starting
to read from the stream is mandatory. In such an instance,
fflush() itself does not necessarily have to appear: fseek() will
also trigger the necessary flushing.
0
i can see you copy entirely from this web and doesn't even give any credit to them:
https://bytes.com/topic/c/answers/629409-fflush-stdout
actually, that is what i didn't understand, thus, i asked here... but instead explain it more clearly, you just copy the content entirely.