Mail Archives: djgpp/1998/02/02/17:27:04
On Sun, 1 Feb 1998, John M. Aldrich wrote:
> Second, MS-DOS text files signal EOL with a CR/LF pair. When reading
> such a file into memory, the extra LF is automatically stripped.
> Likewise, when writing a text file, EOF terminates the write, and CR's
> are translated into CR/LF.
Minor correction: CR is stripped on read and added on write; LF is
retained.
> The moral of the story: If you are writing text data, use text mode.
> If you are writing binary data, use binary mode. Do NOT mix the two, or
> your programs will almost certainly fail.
Unfortunately, this only works up to a point. One example is
PostScript files, which is mostly text and can be parsed, but can also
have embedded non-printable characters. Another example is when you
must seek into a file using byte counts. In such cases, you must open
and read the file in binary mode, and then remove any excess \r
characters while you process it.
- Raw text -