From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Text / binary implementation differences Date: Sun, 01 Feb 1998 19:02:13 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 28 Message-ID: <34D50D05.1493@cs.com> References: NNTP-Posting-Host: ppp203.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Noam Rotem wrote: > > Hi, > > What is the difference, from the implementation side, between a text file and a binary > one? Does djgpp mark EOF differently in a text file and a binary file? Is there any > difference in the way the stream is buffered or treated? And, BTW, are stdin / stdout > *text* streams? (I understand the logical differences between the two kinds, but not the > actual compiler job around each one). Text mode under DOS has two main differences from binary mode. First, the EOF character (Ctrl-Z) signals the end of the file in text mode. 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. 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. -- --------------------------------------------------------------------- | John M. Aldrich | "Animals can be driven crazy by pla- | | aka Fighteer I | cing too many in too small a pen. | | mailto:fighteer AT cs DOT com | Homo sapiens is the only animal that | | http://www.cs.com/fighteer | voluntarily does this to himself." | ---------------------------------------------------------------------