when fflush call is needed?

J

Jack Klein

hi all,

when fflush function must be called? and why?

thanks

baumann@pan

fflush(), or a file positioning function, must be called after writing
to a file opened in append mode before reading from the file. But the
fseek() or fsetpos() could be used as well, and indeed must be used
after reading from a file opened in append mode before writing to it.

There is no situation where the fflush() function must be called at
all.

There are cases where it is advisable to do so. The most particular
one is if a prompt that does not end in a '\n' is sent to the standard
output prompting for user input. On some systems, the prompt may not
appear on the terminal or display until after the user ends his input
with the 'enter' or 'return' key, unless you fflush() stdout before
calling the input function on stdin.
 
A

August Karlstrom

baumann@pan said:
hi all,

when fflush function must be called? and why?

thanks

baumann@pan

A simple (and incomplete) explanation:

fflush will write all pending output to its file immediately.

Since it's a quite costly operation the standard library output
functions does not do this by default.


-- August
 
M

Mark McIntyre

when fflush function must be called? and why?

When you want to flush output.
Because you want to flush output.

( This is a homework question, right? )
 
B

baumann@pan

Mark said:
When you want to flush output.
Because you want to flush output.

( This is a homework question, right? )
no, i just wonder
why printf("abcd"); may not work properly.
but printf("abcd\n"); would work.

and i remember in some post someone wrote when fflush must be needed.

but i have not write it down, so i can not remember it.
 
B

baumann@pan

thank u, yours is most in details, thanks much.

Jack said:
fflush(), or a file positioning function, must be called after writing
to a file opened in append mode before reading from the file. But the
fseek() or fsetpos() could be used as well, and indeed must be used
after reading from a file opened in append mode before writing to it.

There is no situation where the fflush() function must be called at
all.

There are cases where it is advisable to do so. The most particular
one is if a prompt that does not end in a '\n' is sent to the standard
output prompting for user input. On some systems, the prompt may not
appear on the terminal or display until after the user ends his input
with the 'enter' or 'return' key, unless you fflush() stdout before
calling the input function on stdin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top