Binary Files (raw bytes)

Up till now we've being playing around with files which contain ASCII text. Can C read files with binary data? Let's find out.

There are many circumstances in which you may want to read from and write to binary files. Binary files are not plain text (ascii) files where each chunk of bytes represents an ascii character. In binary files, you store raw bytes, in whatever format you want. For example, Optotrak stores its data files as binary files: a header of a given length (number of bytes) followed by data, in a specific byte format.

Advantages of binary files over ascii files are as follows:

  • They are typically smaller in size.
  • They can be read from and written to faster (no need to convert between raw bytes and ascii characters).

Disadvantages of binary files are that they are not human-readable (you can’t open in them in a text editor and “look” at them).

Create a free account to access the full course.

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