Date: Mon, 2 Feb 1998 19:05:35 +0200 (IST) From: Eli Zaretskii To: "John M. Aldrich" cc: djgpp AT delorie DOT com Subject: Re: Text / binary implementation differences In-Reply-To: <34D50D05.1493@cs.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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.