[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MinGW/Windows CRLF lunacy
From: |
Lionel B |
Subject: |
Re: MinGW/Windows CRLF lunacy |
Date: |
Mon, 9 May 2005 16:01:25 +0100 |
"Paul Pluzhnikov" wrote :
> Matt wrote:
>
> > What trick do I have to use to make the file contain exactly the data
> > I send to fwrite?
>
> Perhaps open the file in binary mode?
>
> fopen("output", "wb");
To expand on that a little, under (most?) unixes, there is no difference
between "text" and "binary" mode for files. In
Windows, however, reading a file opened in text mode converts \r\n (CR/LF pair)
to \n, while writing does the converse -
i.e. \n gets written as \r\n - this is the extra byte you are seeing.
See:
http://new-brunswick.net/workshop/c++/faq/input-output.html#faq-15.12
and:
http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#3
for more info.
Regards,
--
Lionel B