Mail Archives: djgpp/1995/02/03/18:41:12
On Fri, 3 Feb 1995, Brian Smith wrote:
> I have installed djgpp with gcc version 2.6.0. I am trying to use
> fwrite to write a static character array to a dos file. When I look
> at the output file with debug, I find that all of my 0xa (LF) have
> been replaced by 0x0d 0x0a (CR/LF).
DOS has two file write modes, binary and text. Binary mode is "raw",
byte for byte output, text is "cooked" and performs the transformation
you noticed. Hence, if a file is opened in text mode, all newlines are
written as CR/LF and on reading all CR/LF become newlines. The default
file open mode under DOS is text, so if you want to write in binary mode
you must tell fopen(), like this:
fp = fopen ("myfile.ext", "wb");
that is, you must append the letter 'b' to the mode specifier.
Bill Davidson
bdavidson AT ra DOT isisnet DOT com
- Raw text -