Re: \n to \r\n in stdout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
fp1=fopen("source.zip","rb");
fp2=fopen("destiny.zip","wb");
while(!feof(fp1)) fputc(fgetc(fp1),fp2);
fclose(fp1);
fclose(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));
fclose(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
file.

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

Gratefully,
Thales Medeiros.


Citando John Love-Jensen <eljay@xxxxxxxxx>:

> 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.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux