[sclug] C programming question

James Fidell james at cloud9.co.uk
Sat Oct 25 09:05:38 UTC 2003


Quoting Andy Arbon (sclug at andrewarbon.co.uk):
> Hello All,
> 
> I'm helping a mate with some C programming, but I'm not exactly a guru 
> myself, and I'm a bit puzzled by a problem I'm hitting.
> 
> I have the two (hopefully attached) files. primary is a binary datafile, 
> showpri.c is code that should read it and display it.
> 
> The problem is that when it runs it displays a load of rubbish (couple 
> of lines quoted below). The data is supposed to be from a radar, to give 
> you some context. This means that negative range readings and enourmous 
> bearing angles are unlikely to be correct.
> 
> Can anyone tell me what's wrong with it? The datafile was probably 
> produced on Windows and I'm running the code on Linux - is there any 
> difference in the file I/O between the two that could account for this?
> 
> My primitive C skills say that the code is all OK, so I'm wondering if 
> it's one of those little-known-quirks type problems that I don't know about.

Do you know that the byte-ordering, alignment, size and format of the
data written in the file is the same as your C compiler is using for the

>   struct primary_plot {
>       double   bearing;
>       int      range;
>       double   elevation;
>   };

?

James



More information about the Sclug mailing list