Moving Around Within Binary Files

One of the benefits of working with binary files is that it's very easy to move around within the binary data. When you open a file, C creates a marker pinpointing a location within this file. (This marker is commonly called a pointer but we don't want to confuse you since it's not the same kind of pointer you've been working with.) When you read from a file, the data is read and the marker is moved forward. When you write, the data is added at that location and, again, the marker is moved forward.

You can also move the marker directly to a specific point using fseek():

fseek(fp, offset, starting_point);

The first argument is our file pointer, which refers to an opened binary file. The second argument dictates ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.