scott@bent.mc.duke.edu (Scott Woskoff) (09/26/89)
Has anyone written more robust, flexible replacements for atoi() and atol()? Also looking for related functions for hex and unsigned, and functions that can recognize these strings but don't convert them. An example of 'our' definitions of integers, floats, hex, and unsigned follows. Please, no flames; I didn't come up with these definitions (or examples). Also, any related functions would be appreciated. These are all being used to validate user input. Please respond to me directly; I normally don't read this newsgroup. Thanks. -Scott -- Scott Woskoff (aka W0UG) GE Medical Systems Computer Systems Engineering Milwaukee, WI -- scott@gemed.med.ge.com ...uunet!crdgw1!gemed!scott ...{ucbvax,hplabs,decvax}!sun!texsun!gemed!scott [Integer] The string may consist of an optional string of "white-spaces", then an optional sign, followed by decimal digits. No space is allowed between the sign and the decimal digits. ex. "2" --> 2 "a2" --> error "+2" --> 2 "2b" --> error "-2" --> -2 "2 3" --> error " 2" --> 2 "- 2" --> error "2 " --> 2 "+" --> error " +2" --> 2 "-" --> error " 2" --> 2 " " --> error "+0" --> 0 "\0" --> error "002" --> 2 NIL --> error [Floats] The string may consist of an optional string of "white-spaces", then an optional sign, then string of digits optionally containing a decimal point, then an optional e or E, followed by an optional sign, followed by an integer. No space is allowed between each parts. ex. "2" --> 2.0 "a2.0" --> error "+2" --> 2.0 "2.0b" --> error "-2" --> -2.0 "- 2.0" --> error " 2" --> 2.0 "2. 0" --> error "2 " --> 2.0 "." --> error " 2" --> 2.0 "-." --> error "+0" --> 0.0 "e2" --> error "2.0" --> 2.0 "E-3" --> error "2." --> 2.0 ".e" --> error ".5" --> 0.5 ".e2" --> error ".0" --> 0.0 "2e 2" --> error "0." --> 0.0 "+" --> error "+.5" --> 0.5 " " --> error "2.0E3" --> 2000.0 "\0" --> error "2.0e-3" --> 0.002 NIL --> error [Hex] The string may consist of an optional string of "white-spaces", then an optional sign, followed by hexadecimal digits. No space is allowed between the sign and the hexadecimal digits. ex. "2" --> 2 "+ 0" --> error "f" --> 15 "2g" --> error "F" --> 15 "2 3" --> error " 2" --> 2 "+" --> error "2 " --> 2 "-" --> error " 2" --> 2 " " --> error "a2" --> 162 "\0" --> error "+0" --> 0 NIL --> error "-2f" --> -47 [Unsigned] The string may consist of optional string of "white-spaces", followed by decimal digits. ex. "2" --> 2 "a2" --> error " 2" --> 2 "2b" --> error "2 " --> 2 "2 3" --> error " 2" --> 2 "+2" --> error "002" --> 2 "+" --> error "-" --> error " " --> error "\0" --> error NIL ---> error -- Scott Woskoff (aka W0UG) GE Medical Systems Computer Systems Engineering Milwaukee, WI -- scott@gemed.med.ge.com ...uunet!crdgw1!gemed!scott ...{ucbvax,hplabs,decvax}!sun!texsun!gemed!scott