Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!wuarchive!uunet!bu.edu!m2c!wpi.WPI.EDU!fenn From: fenn@wpi.WPI.EDU (Brian Fennell) Newsgroups: comp.lang.c Subject: Re: Implicit decimal points in floating-point reads Keywords: scanf,floating point,decimal formats Message-ID: <1991May21.200003.13471@wpi.WPI.EDU> Date: 21 May 91 20:00:03 GMT References: <5366@dftsrv.gsfc.nasa.gov> Organization: Worcester Polytechnic Institute Lines: 31 In article <5366@dftsrv.gsfc.nasa.gov> brotzman@nssdca.gsfc.nasa.gov writes: > The problem I am encountering is this: FORTRAN allows input strings >representing floating point values to have implicit decimal places, i.e. >the string "26208" read with a format of F5.3 results in a value of 26.208. >As far as I can tell there is no equivalent functionality in C, I have tried >using scanf with an input format of "%5.3f", but the result is garbage (see >below). I think the answer is "you can't get there from here." >Please tell me that I'm being a bonehead and missing something obvious. :-) no bonehead about it, but since this is something you need a fix for, not a how-do-I-write-like-a-real-C-Guru-would, try this... >---------------------------< TEST.C >--------------------------------- >#include > >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 */ > printf("%s %f\n%s %i", "input string converted to: ", x, > "number of parameters converted: ", ifld); >} Brian Fennell == fenn@wpi.wpi.edu