Fseek versus rewind?

I noticed two methods to return to the beginning of the file

FILE *fp = fopen("test.bin", "r") fseek(fp, 0, SEEK_END); rewind(fp); 

and

 FILE *fp = fopen("test.bin", "r") fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_SET); 

What is the difference between these methods?

+14
source share
2 answers

Basically, these are two different ways to do the same thing: set the pointer to the beginning of the file. The only difference is that rewind also clears the error indicator.

If you need a choice, you should use fseek . This is because rewind does not return an integer indicating whether the operation succeeded.

+17
source

If fseek() returns success, it will also clear the end-of-file indicator, whereas rewind() does not.

+4
source

Source: https://habr.com/ru/post/1259269/


All Articles