[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


strtod

Character array conversion to floating point value of type double.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdlib.h>
double strtod( const char *nptr,
  char **endptr);
Parameters:

Parameters for this facility are:

nptr  
const char *  
A Null terminated array to convert  
endptr  
char **  
A pointer to a position in nptr that is follows the converted part.  

Remarks:

The strtod() function converts a character array, pointed to by nptr, to a floating point value of type double. The character array can be in either decimal or hexadecimal floating point constant notation (e.g. 103.578, 1.03578e+02, or 0x1.9efef9p+6).

If the endptr argument is not a null pointer, it is assigned a pointer to a position within the character array pointed to by nptr. This position marks the first character that is not convertible to a value of type double.

This function skips leading white space.

This function sets the global variable errno to ERANGE if there is a conversion error.

Return:

strtod() returns a floating point value of type double. If nptr cannot be converted to an expressible double value, strtod() returns HUGE_VAL, defined in math.h, and sets errno to ERANGE.

See Also:

"strtol"

"strtoul"

"errno"

"Integral type limits"

"Overview of math.h"

"scanf"

Example of strtod() and strtold() usage.:
#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