5

If I encounter feof() and then stat shows that the file has grown, is there a way to read the added data without doing a fclose() and fopen()?

Fixee
  • 1,581
  • 2
  • 15
  • 25
  • See [here](http://stackoverflow.com/questions/11757304/how-to-read-a-growing-text-file-in-c) and [here](http://stackoverflow.com/questions/7864769/c-reading-from-a-live-file-file-keep-growing-in-size). –  Sep 22 '13 at 05:36
  • Thanks @Tsukuyo, but the first link is C++ which uses a different set of file i/o calls, and the second says to use `select()` which doesn't seem viable (as far as I understand `select()` at any rate). – Fixee Sep 22 '13 at 05:41

1 Answers1

8

Yes. You can call clearerr on the file, or perform any seek opereration such as fseek(f, 0, SEEK_CUR).

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • `fseek(f, 0, SEEK_CUR)` clears the `eof` flag? That's news to me (and quite helpful!). – Fixee Sep 22 '13 at 05:43
  • 1
    C99 7.19.9.2 The fseek function, paragraph 5: "After determining the new position, a successful call to the fseek function undoes any effects of the ungetc function on the stream, clears the end-of-file indicator for the stream, and then establishes the new position." – R.. GitHub STOP HELPING ICE Sep 22 '13 at 06:15