I have read this about the switch between read and write operations(and vice-versa) for files opened for update using fopen()
(LINK)
\"For files ope
You nailed the 2nd point correctly i.e. if we reach EOF and then we intend to write its fine, its just like fseek
to SEEK_END
.
But for the 1st point it is needed that we take a reference point to start the read operation after write operation i.e. because suppose that you are trying to overwrite some dynamic data in the file so the length may vary depending upon that you may not get the exact position which you are thinking.
example: say file test.txt has data hello world
you want to update the hello
text to some other text say share
so according to you the text should be share world
. Hence the length is same you will get the exact output but what about replacing hello
with bye
or someother
text then you will either get garbage data or no data(if replace string is too long)