c - Why is fseek or fflush always required between reading and writing in the update modes? -


q: i'm trying update file in place, using fopen mode "r+", reading string, , writing modified string, it's not working.

a: sure call fseek before write, both seek beginning of string you're trying overwrite, , because fseek or fflush required between reading , writing in read/write "+" modes.

my question why fseek or fflush required between reading , writing in read/write "+" modes? section 5.2 of andrew koenig's c traps , pitfalls (1989) mentioned because of backward compatibility issue. can explain in detail?

the library buffers input , output operations. check out setvbuf() , _iofbf, _iolbf parameters funktion. fseek() or fflush() require library commit buffered operations. standard specifies seek or flush operation mandatory allow library shortcuts; otherwise, every i/o operation, lib have check if previous operation read op (or write op), , trigger flush if "direction" of i/o changed.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -