|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: C sizes trouble - reading longs from a file
Hmm... Well, I think I'll use the fread() method, but I'll use 4 instead of
sizeof(long), would this be correct? Since no matter what the operating
system, the data in the file will STILL be 4 bytes long! :-) I think it
would even be easier to rewrite the piece of code, than to change the
entire data file structure :-).
Thanks for the help,
Ciao,
Lionel
----------
From: slick willy <bporter@flashcom.net>
To: gameprogrammer@gameprogrammer.com
Subject: Re: C sizes trouble - reading longs from a file
Date: Monday, August 28, 2000 8:15 PM
shouldn't this:
offset = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) +
buffer[0];
be this?:
offset = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) +
buffer[3];
also, as someone said earlier, you should make your code more portable by
checking the sizeof(long) since on many machines a long is in fact not 4
bytes.
--Bill
----- Original Message -----
From: Lionel Pinkhard
To: gameprogrammer@gameprogrammer.com
Sent: Thursday, January 03, 1980 3:07 PM
Subject: C sizes trouble - reading longs from a file
Hey guys,
I'm having some trouble here, I have a data file which contains an offset
to another location in the file. The offset is a long (4 bytes). I need
to
read in the offset from a location in the file, and then move the file
pointer to the location specified by that long. I have tried using the
following code:
for (index = 0; index < 4; index++) {
buffer[index] = fgetc(data_p);
}
offset = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) +
buffer[0];
fseek(data_p, offset, 0);
But this doesn't seem to set me at the right location. And if I try
printing out the data pointed to by the offset, I just get EOFs.
What am I doing wrong? Is there a simpler way of doing this?
I really hope somebody can help me out here!
Ciao,
Lionel
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once
To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once
To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
|
|