Jay Patel Jay Patel - 1 month ago 6
C Question

Data that is written into and read from remain unchanged in binary file?

I am Reading about Binary and Text files, and I came across this:

Binary file is a collection of bytes. In C, a byte and
a character are equivalent. Hence, a binary fi le is also
referred to as a character stream, but there are two essential
differences.

Firstly, the data that is written into and read from
remain unchanged
, with no separation between lines and
no use of end-of-line characters. The NULL and end-of-
line characters have no special significance and are treated
like any other byte of data.

What this line mean "Firstly, the data that is written into and read from remain unchanged?"

Answer

The book is contrasting the process of writing to a binary file and the process of writing to a text file.

When you write a sequence of bytes to a binary file, that is the exact sequence that would be stored in the file. When you read the file back, you get the exact sequence that you wrote into it.

This is not the case for files processed in text mode due to whitespace handling that is built into API for reading from text files. Whitespace is treated as text separators, so most API would not return whitespace to you, thus "altering" the representation of the exact sequence of bytes stored in the file.