A
Andrew Kibler
Two sections of code, in the first one fwrite works, in the second one
it doesn't (ms VC++) both are identical except in the working one fseek
is used twice to set the file pointer, once just before the fwrite.
WHY???
Works:
fseek(fp, itemloc, SEEK_SET);
tmp = ReadLongBE(fp);
if (*itemsize == tmp){
printf("\n%X\n",ftell(fp));
fseek(fp, itemloc + 4, SEEK_SET); //added to make fwrite
work.
r += fwrite(itemdata, 1, *itemsize, fp);
printf("\n%X\n",ftell(fp));
Just goes through the motions, but doesn't write (even returns proper
values!!)
fseek(fp, itemloc, SEEK_SET);
tmp = ReadLongBE(fp);
if (*itemsize == tmp){
printf("\n%X\n",ftell(fp));
//no fseek, but ftell is correct.
r += fwrite(itemdata, 1, *itemsize, fp); //but this doesn't actually
write!!
printf("\n%X\n",ftell(fp)); //but the file pointer is advanced
properly
BOTH return the same values for ftell before and after the write.
The second one doesn't wrrite, but acts like it does during the debug.
The ReadLongBE (big endian) macro:
#define ReadLongBE(Stream) ((getc(Stream)<<24) + (getc(Stream)<<16) +
(getc(Stream)<<8) + (getc(Stream)))
Thanks!
it doesn't (ms VC++) both are identical except in the working one fseek
is used twice to set the file pointer, once just before the fwrite.
WHY???
Works:
fseek(fp, itemloc, SEEK_SET);
tmp = ReadLongBE(fp);
if (*itemsize == tmp){
printf("\n%X\n",ftell(fp));
fseek(fp, itemloc + 4, SEEK_SET); //added to make fwrite
work.
r += fwrite(itemdata, 1, *itemsize, fp);
printf("\n%X\n",ftell(fp));
Just goes through the motions, but doesn't write (even returns proper
values!!)
fseek(fp, itemloc, SEEK_SET);
tmp = ReadLongBE(fp);
if (*itemsize == tmp){
printf("\n%X\n",ftell(fp));
//no fseek, but ftell is correct.
r += fwrite(itemdata, 1, *itemsize, fp); //but this doesn't actually
write!!
printf("\n%X\n",ftell(fp)); //but the file pointer is advanced
properly
BOTH return the same values for ftell before and after the write.
The second one doesn't wrrite, but acts like it does during the debug.
The ReadLongBE (big endian) macro:
#define ReadLongBE(Stream) ((getc(Stream)<<24) + (getc(Stream)<<16) +
(getc(Stream)<<8) + (getc(Stream)))
Thanks!