Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!elroy.jpl.nasa.gov!jpl-devvax!ai-ganymede!charest From: charest@ai-ganymede.JPL.NASA.GOV (Len Charest) Newsgroups: comp.lang.c Subject: i/o of floats Message-ID: <9232@jpl-devvax.JPL.NASA.GOV> Date: 21 Aug 90 22:43:10 GMT Sender: news@jpl-devvax.JPL.NASA.GOV Reply-To: charest@AI-Cyclops.JPL.NASA.GOV Organization: NASA/Jet Propulsion Laboratory Lines: 29 I have a large (~40 MB) file of floating point values stored in binary under the following format: float = 32-bit word bit 31 = sign bit for exponent bits 30-23 = exponent (8 bits) bits 22-0 = mantissa (always positive) (Apparently this is some IEEE standard.) 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. Example: let N = 256 /* N is known a priori for now */ unsigned char record[N + 1]; /* add one for terminating `\0` */ fscanf(fp, "%256s", record); /* read the record from disk */ Now how do I interpret each 4-byte "word" of record as a floating point number? I merely need to print each float onto stdout. However, I've been away from C programming for a while and I'm confused about how to solve this problem. I am assuming that the fscanf library function does not alter the bits it reads when the conversion spec indicates a character string. That is, interpretation of the raw bits stored on file should be completely under my control. On the other hand, I really would like to avoid writing a mammoth floating point conversion routine. Suggestions/solutions are greatly appreciated. Respond to this list or directly to me at charest@ai-cyclops.jpl.nasa.gov Thanx, Len