|
||
|
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
Lionel,
instead of:
for (index = 0; index < 4; index++) {
buffer[index] = fgetc(data_p);
}
offset = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) +
buffer[0];
use:
fread( &offset, sizeof(long), 1, data_p );
because
A) it is easier to look at
B) it is now more portable (the compiler will figure out how big the "long"
is for you)
C) it is less error prone due to it's simplicity
Whether or not this solves your problem, it is a good idea to code it this
way.
Also, don't assume the code is the problem: are you certain that the data
file is intact?
Good luck,
Ben.
"the currency of methods are cpu cycles
and the currency of properties are bytes
waste neither of them, keeping in mind that
the currency of the problem domain is thought
infinitely more scarce in comparison"
-jplindstrom
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
=================================================================
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
|
|