Everything

strtod


Conversion of character string to floating-point number (double type) (storing pointer in last character string)

[Classification]

Standard library

[Syntax]

#include <stdlib.h>

double strtod(const char *str, char **ptr);

[Return value]

If the partial character string has been converted, the resultant value is returned. If the character string could not be converted, 0 is returned.

If an overflow occurs (the value is not in the range in which it can be expressed), HUGE_VAL or -HUGE_VAL is returned, and ERANGE is set to global variable errno. If an underflow occurs, 0 is returned, and macro ERANGE is set to global variable errno.

[Description]

This function converts the first part of the character string indicated by str into a float type representation. The part of the character string to be converted is in the following format and is at the beginning of str with the maximum length, starting with a normal character that is not a space.

 

[ + | - ] digits [ . ] [ digits ] [ (e | E) [ + | - ] digits ]

 

If str is vacant or consists of space characters only, if the first normal character is other than "+", "-", ".", or a numeral, the partial character string does not include a character. If the partial character string is vacant, conversion is not executed, and the value of str is stored in the area indicated by ptr. If the partial character string is not vacant, it is converted, and a pointer to the last character string (including the null character (\0) indicating at least the end of str) is stored in the area indicated by ptr.

Remark

This function is not reentrancy.

#include    <stdlib.h>
typedef struct {
        double  d[3];
        int     i[2];
} s_data;
int func(void) {
        sdata   *buf;
        if((buf = calloc(40, sizeof(s_data))) == NULL)  /*allocate an area for 40 
                                                          s_data*/
                return(1);
           :
        free(buf);                                      /*release the area*/
        return(0);
}