Mail Archives: djgpp-workers/2008/04/08/11:30:29
Linux parses what it can of the string, stopping at the first
non-numeric character. Thus, "123.456 E+12" parses as 123.456 for all
three functions.
The Linux man page documents it that way; it converts "the initial
portion of the string". *endptr points to the first character after
the number parsed.
DJGPP's documentation says the same: "This function converts as many
characters of @var{s} that look like a floating point number into that
number."
So, just stop at the space. strtold is right, the other two need
fixing.
#define _XOPEN_SOURCE 600 /* or #define _ISOC99_SOURCE */
#include <stdio.h>
#include <stdlib.h>
main()
{
float f;
double d;
long double l;
char *str = "123.456 E+2";
char *estr;
f = strtof (str, &estr);
d = f;
printf("strtof %f %d\n", d, estr-str);
d = strtod (str, &estr);
printf("strtod %f %d\n", d, estr-str);
l = strtold (str, &estr);
d = l;
printf("strtold %f %d\n", d, estr-str);
}
- Raw text -