Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: i/o of floats Message-ID: <3598@goanna.cs.rmit.oz.au> Date: 22 Aug 90 03:20:28 GMT References: <9232@jpl-devvax.JPL.NASA.GOV> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 24 In article <9232@jpl-devvax.JPL.NASA.GOV>, charest@ai-ganymede.JPL.NASA.GOV (Len Charest) writes: > I have a large (~40 MB) file of floating point values stored in binary > [using IEEE-754 single precision (32-bit) format] > The floats are stored in contiguous "records" of length N, where N is > determined at *run-time*. This means that I can minimize the number of > calls to fscanf by reading an entire record of floats from the disk (as > an array of chars) and then parsing the record in C. Ick. You can't use fscanf() with such data *at all*. fscanf() is for reading *text*. To read a record of N bytes as N/4 floats, do #define N /*whatever*/ #define NFLOATS ((N)/sizeof (float)) float the_record[NFLOATS]; int floats_read; ... floats_read = fread(the_record, sizeof (float), NFLOATS, the_stream); Now you have 32-bit floats in memory and can do printf("%g", the_record[floats_read-1]) or whatever takes your fancy. -- The taxonomy of Pleistocene equids is in a state of confusion.