A problem of GCC

Hi mates,
I am a new comer of this forums.
I have a problem while using function "fread(buffer, size, number, file-pointer)" to read a binary file.

While I used the "fread\(\)" to read the binary file under Solaris UNIX System, it worked very well.  But it gets a incorrect result when I try the same program under LINUX\(Red Hat\) System.  I have tried for about  5 times, still can't find the answer.
Anyone who knows the reason?

Please give me a hand. Thank you.

Best Regard.

YANG Liping

email addresses removed

There is a link to our rules at the bottom of every page. Please read them.

If we knew more about your data and what your code does it might help someone give you good answer

It's a binary file.

there are two integers(4 bytes) and two short integers (2 bytes) at the beginning of the file I want to read. Following that are some float numbers.

I asked some mates, they said that the reason maybe because of the different byte-order between UNIX and Linux. But I don't know how to handle such problem.

Just make sure you use the same byte ordering for reading and writing. Big endian (network byte order) or little endian (host byte order) does not matter. See htonl/htons/ntohl/ntohs for conversion functions between the two byte orderings.

Or, if applicable, write numbers in ASCII string format and cast it back with functions like sscanf. No byte-ordering problem exists in this case.

As a beginner of Linux, I am not very clear with the filesystem of Linux. Where can I find the conversion functions between the two byte orderings