Fread apparently knows the place where it last stopped, by that I mean this:
while(fread(buffer, 1, 1, file))
{
…
}
This loop would continue the next time where it stopped the last time. I assume it just moves the file pointer forward, but could someone explain if it’s exactly like that?
CodePudding user response:
The function fread
reads from a stream, which is not necessarily a file. Streams can also be linked to consoles/terminals. Some streams are seekable and have a file position indicator, some do not. Streams which are linked to actual files usually do have a file position indicator.
The function fread
itself does not advance any file position indicator (it does not call fseek
). It just reads from the stream.
If a stream has a file position indicator, then the runtime library will advance the file position indicator, whenever a read takes place on the stream. It does this for all reads on the stream, not just for fread
.