Character array conversion to floating point value of type double.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdlib.h>
double strtod( const char *nptr,  
char **endptr);
Parameters for this facility are:
This function skips leading white space.
This function sets the global variable errno to ERANGE if there is a conversion error.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
double f;
long double lf;
static char sf1[] = "103.578 777";
static char sf2[] = "1.03578e+02 777";
static char sf3[] = "0x1.9efef9p+6 777";
char *endptr;
f = strtod(sf1, &endptr);
printf("Value = %f remainder of string = |%s|\n", f, endptr);
f = strtod(sf2, &endptr);
printf("Value = %f remainder of string = |%s|\n", f, endptr);
f = strtod(sf3, &endptr);
printf("Value = %f remainder of string = |%s|\n", f, endptr);
lf = strtold(sf1, &endptr);
printf("Value = %lf remainder of string = |%s|\n", lf, endptr);
lf = strtold(sf2, &endptr);
printf("Value = %lf remainder of string = |%s|\n", lf, endptr);
lf = strtold(sf3, &endptr);
printf("Value = %lf remainder of string = |%s|\n", lf, endptr);
return 0;
}
Output:
Value = 103.578000 remainder of string = | 777|
Value = 103.578000 remainder of string = | 777|
Value = 103.748997 remainder of string = | 777|
Value = 103.578000 remainder of string = | 777|
Value = 103.578000 remainder of string = | 777|
Value = 103.748997 remainder of string = | 777|
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000