Menu

Commit [r349]  Maximize  Restore  History

- strtoimax(), strtoumax(), strtod(), strtof(), strtol(), strtoll(),

strtoul() and strtoull() now count how many digits were converted.
If that number is zero, then the conversion is considered to have
failed: 0 is returned, errno is set to ERANGE and the 'ptr' parameter
reference is initialized with a pointer to the string to be converted.
This has two consequences:

1) A floating point number that has no digits in the significand
is no longer converted to zero. For example ".e10" can no longer
result in a successful conversion.

2) You can detect if a conversion is successful by comparing pointers
after the conversion function has returned:

char * str;
char * ptr;
long n;

n = strtol(str,&ptr,10);
if(n == 0 && str == ptr)
printf("conversion has failed");

obarthel 2005-09-28

changed /trunk/library/changes
changed /trunk/library/inttypes_strtoimax.c
changed /trunk/library/inttypes_strtoumax.c
changed /trunk/library/stdlib_strtod.c
changed /trunk/library/stdlib_strtof.c
changed /trunk/library/stdlib_strtol.c
changed /trunk/library/stdlib_strtoll.c
changed /trunk/library/stdlib_strtoul.c
changed /trunk/library/stdlib_strtoull.c
/trunk/library/changes Diff Switch to side-by-side view
Loading...
/trunk/library/inttypes_strtoimax.c Diff Switch to side-by-side view
Loading...
/trunk/library/inttypes_strtoumax.c Diff Switch to side-by-side view
Loading...
/trunk/library/stdlib_strtod.c Diff Switch to side-by-side view
Loading...
/trunk/library/stdlib_strtof.c Diff Switch to side-by-side view
Loading...
/trunk/library/stdlib_strtol.c Diff Switch to side-by-side view
Loading...
/trunk/library/stdlib_strtoll.c Diff Switch to side-by-side view
Loading...
/trunk/library/stdlib_strtoul.c Diff Switch to side-by-side view
Loading...
/trunk/library/stdlib_strtoull.c Diff Switch to side-by-side view
Loading...
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.