If I open a binary file in text mode and use text functions to
Just to clarify (for the OP's sake), all files are binary files. But
What prohibits an implementation from refusing to open files in a mode
(text vs. binary) other than the one they were created with? (I don't
know of any, but the DeathStation 9000 seems like a likely candidate.)
An implementation could also store binary and text files differently,
e.g. a binary file is on a data track with a block size of 2048, and
text files are on an audio track with a block size of 2352, so you
can't read them correctly in the wrong mode.
some store values represented as text while others store raw binary
values.
However, a file stream may be opened in either binary or text mode.
This may (depending on the system) cause some translation of the bytes
read in or written out. For example, on a particular system a newline
sequence may be stored as a carriage return character followed by a
line feed character but is translated to a single newline character
when read in.
There may be other translations too. For example, one well known
system truncates a text stream after a certain control character is
written to it. (You alude to this below, Gordon.)
Partially true, but some functions naturally lend themselves to
reading/writing text while others are naturally more suited to
reading/writing binary values.
This much I'll agree to.
Actually, some functions require their
input to be text or they write text.
You wouldn't read a raw binary
value with fscanf(), for example, because it parses formatted text.
This doesn't mean there is no formatted text within a binary file.
Assuming for the moment that the binary file is a SQL database or
something similar, even though the rest of the file is heavily
binary, you can still seek to the VARCHAR field and try to parse
it if it's in a known format, say, a serial number with pieces that
mean something (year of manufacture, country code, engine type,
etc. which are encoded into automobile VINs). An automobile VIN
would probably be stored as text, as it's not all numeric, and
storing individual pieces as raw binary does not necessarily save
any space and complicates rather than speeds lookups.
You could read text with fread(), but it won't parse it and extract
values from it (as fscanf() will).
Correct, but if the lines are known to be fixed-length, it's a
perfectly good way of reading them. It's also a perfectly good way
of dealing with the file if you're not trying to interpret the
content (e.g. a file copy, just checksumming the bytes, compressing
the file, or packing a bunch of files into a larger one).