Flushing fopen()'ed files opened in update mode,between read and write operations.Explicit flushing needed?

ⅰ亾dé卋堺 提交于 2019-11-29 14:56:02

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!