Random Access

Learn how to jump to a different location when reading or writing to a file.

We'll cover the following

The need to move around

Sometimes when reading from or writing to file, we may want to jump to a different location in the file and start reading or writing from there. The fseek function lets us do exactly that. We can give the number of bytes after which the read or write is to take place. This is done by specifying a physical location and the offset in number of bytes from that location.

A physical location can be specified as one of the following arguments to fseek:

  • SEEK_SET: The beginning of the file
  • SEEK_CUR: The current position in the file.
  • SEEK_END: The end of the file.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy