|
From: Per W. <pw...@ia...> - 2003-01-28 09:55:59
|
Just as long as you are aware that strtod, strtof, strtol, ... can perform tricks that sscanf can not. sscanf works reasonable for processing a configuration file with known contents. It doesn't work when parsing a language, or an expression, since you don't know the contents of the line until you have parsed it. /Per W On Tue, 28 Jan 2003, Ioannis Vranos wrote: > -------Original Message------- > > From: Per Westermark > Date: =D4=F1=DF=F4=E7, 28 =C9=E1=ED=EF=F5=DC=F1=E9=EF=F2 2003 10:43:25 = =F0=EC > To: Ioannis Vranos > Cc: dev...@li... > Subject: Re: [Dev-C++] atof 2... > > sscanf can convert one or multiplie parameters from a text string into > corresponding variables. The problem is that you have very little control > of what sscanf considers white characters etc. And in case of a conversio= n > problem, it isn't easy to point exactly at the failing character. > > With strtod, you get a pointer to the first un-processed character of you= r > input string. For a parser, the normal action is to process characters on= e > at a time - that means that strotod is never called unless the parser > knows that the first character is the start of a number, i.e. the next > character to process is 0-9 or a decimal separator (. or , depending > on locale). Uppon return of atrtod, the parser may then immediately > continue parsing at the endptr position. > > /Per W > > > =3D=3D> Yes it's a nice for-double-only valid way too. But i prefer sscan= f() for > all this kind of stuff. :) > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys |