\n to \r\n in stdout

thales@virtualbs.com.br thales@virtualbs.com.br
Mon Nov 7 12:40:00 GMT 2005

Hi, John!

The file was already opened in binary mode. The problem isn't in the file
opened, but in the file outputed. Understand what's happening:

FILE *fp1, *fp2;
while(!feof(fp1)) fputc(fgetc(fp1),fp2);

This works! But I don't want to copy files. I need to open the source.zip and
send it to the stdout! So I tried this:

FILE *fp1=fopen("source.zip","rb");
while(!feof(fp1)) putchar(fgetc(fp1));

This doesn't work, because when the character got from the file fp1 is a '\n',
then the program outputs the combination "\r\n" in place. This corrupts the

Thanks for the attention and for the fast answer! I hope you can help me.

Thales Medeiros.

Citando John Love-Jensen <eljay@adobe.com>:

> Hi Thales,
> > I'm trying to open a binary file and print it to the stdout, but
> substituting
> '\n' for "\r\n", the file generated is corrupted.
> Have you tried opening the file in binary mode?
> #include <fstream>
> std::fstream f("myfile.bin",
>    ios_base::binary | ios_base::in | ios_base::out);
> HTH,
> --Eljay

This message was sent using IMP, the Internet Messaging Program.

More information about the Gcc-help mailing list