Re: Bug with compiler or am I just doing something illegal
- From: "Robbie Hatley" <see.my.signature@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 2 Jul 2008 15:44:38 -0700
"raphfrk" <raphfrk@xxxxxxxxxxxx> wrote, among other things:
while(!feof(fp))
{
c = fgetc(fp);
if( c>=0 )
fputc( c , fpo );
}
In addition to the excellent advice others here gave you,
there's one *HUGE* error here which everyone seems to have
missed somehow: the 0 byte, 0x00, is a perfectly
valid byte both for text files (ASCII, iso-8859-1, etc)
and binary (non-text) files. Many of the bytes in a
bmp file will be 0. If you omit those and close up the
gaps, you will severely corrupt the copy of the original
file. It will NOT render correctly in a graphics viewer
(Paintshop Pro, Internet Explorer, or whatever). It
probably can't even be opened, because the headers will
be screwed up.
So your while loop is wrong from several standpoints.
Try:
// Loop while file pointer is valid, until break:
while (fp)
{
c = fgetc(fp); // ATTEMPT TO READ A BYTE.
if (feof(fp)) break; // BREAK IF READ ATTEMPT FAILED.
else fputc(c, fpo); // COPY EVEN THE "0" BYTES.
}
--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant
.
- Follow-Ups:
- Re: Bug with compiler or am I just doing something illegal
- From: Richard Heathfield
- Re: Bug with compiler or am I just doing something illegal
- From: Kaz Kylheku
- Re: Bug with compiler or am I just doing something illegal
- From: Keith Thompson
- Re: Bug with compiler or am I just doing something illegal
- From: Ben Bacarisse
- Re: Bug with compiler or am I just doing something illegal
- References:
- Bug with compiler or am I just doing something illegal
- From: raphfrk
- Bug with compiler or am I just doing something illegal
- Prev by Date: Re: extract all hotmail email addresses in a file and store in separate file
- Next by Date: Re: About career
- Previous by thread: Re: Bug with compiler or am I just doing something illegal
- Next by thread: Re: Bug with compiler or am I just doing something illegal
- Index(es):
Relevant Pages
|