Date: Fri, 29 Jul 1994 09:49:28 -0400 (EDT) From: Edwin Phillips Subject: Re: help with reading floats from file To: Leendert Combee Cc: djgpp AT sun DOT soe DOT clarkson DOT edu On Fri, 29 Jul 1994, Leendert Combee wrote: > > Hello, > > I have trouble reading binary floating point data (4bytes/value) from a > file generated on a sun/unix into my code compiled with djgpp. > > If I compile and run my code on my sun as well, I have no problem: the > code I use is > > float data[...] ; > File *file ; > > .... > > fread(data,sizeof(float),ns,file) ; > > It doesn't seem to matter whether I open the file as "r" or "rb", whether > I compile with cc or gcc, it all works. If I now compile the same source > with djgpp on my pc, the values that are read from the same file are not > read as proper floats (sizeof(float) is still 4bytes). Do I need to swap > some bytes, has anyone encountered this and knows what the proper format > conversion is between floats in djgpp and floats under unix? > > Many thanks, Leendert. > > The order of bytes is different for a Sun than Intel x86. Also, I don't even know if the floating point format is the same. However, you can try to reorder the bytes after you read them in. Here's something to try after they're read in (just reverse the order of each 32bit word): unsigned char *p; unsigned char *q; unsigned char ch; int i; ... for (i=0; i