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

前端 未结 1 745
春和景丽
春和景丽 2020-12-21 08:47

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

相关标签:
1条回答
  • 2020-12-21 09:05

    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)

    0 讨论(0)
提交回复
热议问题