Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Implicit decimal points in floating-point reads Keywords: scanf,floating point,decimal formats Message-ID: <5889@goanna.cs.rmit.oz.au> Date: 22 May 91 05:21:15 GMT References: <5366@dftsrv.gsfc.nasa.gov> <1991May21.200003.13471@wpi.WPI.EDU> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 20 In article <1991May21.200003.13471@wpi.WPI.EDU>, fenn@wpi.WPI.EDU (Brian Fennell) writes: > >main() > >{ char a1[10] = "26208"; > > float x = 0.0; > > int ifld = 0; > > ifld = sscanf(a1, "%5f", &x); > > x /= 1000.; /* simple, to the point, no fancy fix routines needed */ Simple, to the point, and WRONG. The thing about the Fortran format which the original poster wanted to emulate is that the decimal point is placed implicitly where the format specification says *UNLESS* there is an explicit decimal point in the input field. if (!strchr(a1, '.')) x /= 1.0e5; comes closer. Of course, I don't need to explain to a sophisticated audience why this loses accuracy compared with bending the string, do I? -- There is no such thing as a balanced ecology; ecosystems are chaotic.