liveBook · Manning

Binary data

As explained in Modern C

Binary data is data represented as uninterpreted byte sequences rather than text characters.

A byte sequence can be stored exactly as it exists in a C object, or it can pass through text-stream translation. Binary data requires the first behavior: each byte must be read or written unchanged. section 14.4

Keep these distinctions in view:

  • Text streams may translate newlines, suppress spaces, or convert multibyte characters; those transformations can change binary data's internal structure. section 14.4
  • Binary-mode streams skip translation between the file's external representation and the program's internal representation. section 14.4
  • Use fread and fwrite to transfer size*nmemb bytes, and treat a smaller return value as an error. section 14.4 section 14.6
  • Use ftell and fseek to inspect or change the current file position, measured in bytes from the file's start. section 14.4
1   size_t fread(void* restrict ptr, size_t size, size_t nmemb,
2                FILE* restrict stream);
3   size_t fwrite(void const*restrict ptr, size_t size, size_t nmemb,
4                 FILE* restrict stream);
5   int fseek(FILE* stream, long int offset, int whence);
6   long int ftell(FILE* stream);


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":1}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":10}],[{\"line\":0,\"ch\":11},{\"line\":0,\"ch\":16}],[{\"line\":0,\"ch\":17},{\"line\":0,\"ch\":21}],[{\"line\":2,\"ch\":18},{\"line\":2,\"ch\":22}],[{\"line\":0,\"ch\":23},{\"line\":0,\"ch\":31}],[{\"line\":1,\"ch\":23},{\"line\":1,\"ch\":31}],[{\"line\":2,\"ch\":29},{\"line\":2,\"ch\":37}],[{\"line\":3,\"ch\":24},{\"line\":3,\"ch\":32}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":10}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":10}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":1}],[{\"line\":1,\"ch\":17},{\"line\":1,\"ch\":21}],[{\"line\":3,\"ch\":18},{\"line\":3,\"ch\":22}],[{\"line\":4,\"ch\":14},{\"line\":4,\"ch\":18}],[{\"line\":5,\"ch\":19},{\"line\":5,\"ch\":23}],[{\"line\":0,\"ch\":23},{\"line\":0,\"ch\":31}],[{\"line\":1,\"ch\":23},{\"line\":1,\"ch\":31}],[{\"line\":2,\"ch\":29},{\"line\":2,\"ch\":37}],[{\"line\":3,\"ch\":24},{\"line\":3,\"ch\":32}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":1}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":10}],[{\"line\":2,\"ch\":11},{\"line\":2,\"ch\":17}],[{\"line\":2,\"ch\":18},{\"line\":2,\"ch\":28}],[{\"line\":0,\"ch\":23},{\"line\":0,\"ch\":31}],[{\"line\":1,\"ch\":23},{\"line\":1,\"ch\":31}],[{\"line\":2,\"ch\":29},{\"line\":2,\"ch\":37}],[{\"line\":3,\"ch\":24},{\"line\":3,\"ch\":32}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":10}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":10}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":10}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":1}],[{\"line\":1,\"ch\":17},{\"line\":1,\"ch\":21}],[{\"line\":3,\"ch\":18},{\"line\":3,\"ch\":22}],[{\"line\":4,\"ch\":14},{\"line\":4,\"ch\":18}],[{\"line\":5,\"ch\":19},{\"line\":5,\"ch\":23}],[{\"line\":0,\"ch\":23},{\"line\":0,\"ch\":31}],[{\"line\":1,\"ch\":23},{\"line\":1,\"ch\":31}],[{\"line\":2,\"ch\":29},{\"line\":2,\"ch\":37}],[{\"line\":3,\"ch\":24},{\"line\":3,\"ch\":32}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":1}],[{\"line\":4,\"ch\":4},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":12}],[{\"line\":4,\"ch\":8},{\"line\":4,\"ch\":13}],[{\"line\":1,\"ch\":17},{\"line\":1,\"ch\":21}],[{\"line\":3,\"ch\":18},{\"line\":3,\"ch\":22}],[{\"line\":4,\"ch\":14},{\"line\":4,\"ch\":18}],[{\"line\":5,\"ch\":19},{\"line\":5,\"ch\":23}],[{\"line\":4,\"ch\":28},{\"line\":4,\"ch\":36}],[{\"line\":5,\"ch\":4},{\"line\":5,\"ch\":12}],[{\"line\":4,\"ch\":4},{\"line\":4,\"ch\":7}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":12}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":1}],[{\"line\":4,\"ch\":28},{\"line\":4,\"ch\":36}],[{\"line\":5,\"ch\":4},{\"line\":5,\"ch\":12}],[{\"line\":5,\"ch\":13},{\"line\":5,\"ch\":18}],[{\"line\":1,\"ch\":17},{\"line\":1,\"ch\":21}],[{\"line\":3,\"ch\":18},{\"line\":3,\"ch\":22}],[{\"line\":4,\"ch\":14},{\"line\":4,\"ch\":18}],[{\"line\":5,\"ch\":19},{\"line\":5,\"ch\":23}]]"}
!@%STYLE%@!

These declarations collect the core interfaces for transferring bytes and controlling a binary stream's file position. section 14.4

How Modern C covers it

How deep it goes
Explains translation hazards, binary mode, byte counts, file positions, and error detection, but defers detailed error case analysis.
Examples
Demonstrates newline translation changing binary structure and identifies fread, fwrite, ftell, and fseek as the relevant interfaces.
What it assumes
Assumes familiarity with C streams and objects while distinguishing text processing from binary file operations.
What you can do after
Apply via C library interfaces to transfer binary bytes, navigate file positions, and detect incomplete operations.
How it connects
Connects binary data with text streams, binary files, fread, fwrite, file positions, and platform dependence.

Also explained in

Compare how 4 books explain binary data →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.