ssttrrttoodd() -- General Function (libc)

Convert string to floating-point number
#iinncclluuddee <ssttddlliibb.hh>
ddoouubbllee ssttrrttoodd(_s_t_r_i_n_g, _t_a_i_l_p_t_r)
cchhaarr *_s_t_r_i_n_g; cchhaarr **_t_a_i_l_p_t_r;

ssttrrttoodd()  converts  the  number  given  in  _s_t_r_i_n_g  to  a  double-precision
floating-point number and returns its  value.  It is a more general version
of  the  function aattooff().  ssttrrttoodd()  also  stores a  pointer  to the  first
character  following the  number through _t_a_i_l_p_t_r,  provided _t_a_i_l_p_t_r  is not
NNUULLLL.

ssttrrttoodd() parses  the input _s_t_r_i_n_g  into three portions:  beginning, subject
sequence, and tail.

The _b_e_g_i_n_n_i_n_g  consists of zero  or more white-space  characters that begin
the string.

The  _s_u_b_j_e_c_t _s_e_q_u_e_n_c_e  is the  portion  of the  input _s_t_r_i_n_g  that ssttrrttoodd()
converts into  a floating-point  number.  It  consists of an  optional sign
character,  a nonempty  sequence of decimal  digits optionally  including a
decimal-point  character,  and  an  optional  exponent.   If  present,  the
exponent consists of  either `e' or `E' followed by  an optional sign and a
nonempty sequence  of decimal digits.   ssttrrttoodd() reads characters  until it
encounters either  a second decimal-point character  or exponent marker, or
any other non-numeral.

The  _t_a_i_l continues  from  the end  of  the subject  sequence  to the  null
character that ends the string.

ssttrrttoodd()  ignores the  beginning portion  of the  string.  It  converts the
subject  sequence  to  a double-precision  number.   Finally,  it sets  the
pointer pointed to by _t_a_i_l_p_t_r to  the address of the first character of the
string's tail.

ssttrrttoodd() returns  the ddoouubbllee  generated from  the subject sequence.   If no
subject  sequence  could be  recognized,  it returns  zero  and stores  the
initial value  of _s_t_r_i_n_g through _t_a_i_l_p_t_r. If the  number represented by the
subject  sequence is  too large  or too  small to fit  into a  ddoouubbllee, then
ssttrrttoodd() sets  the global constant eerrrrnnoo to EERRAANNGGEE  and returns HHUUGGEE_VVAALL or
zero, respectively.  If, however,  the number given in the subject sequence
has  more digits  to the  right of  the decimal point  than can  be encoded
within an IEEE  ddoouubbllee (which has a fraction of  53 bits), ssttrrttoodd trims the
excess digits before it converts the string.

_E_x_a_m_p_l_e
The following gives an example for ssttrrttoodd().

#include <stdlib.h>

main()
{
    static char st[] = " 123.4 567.8";
    char *head, *tail;

    for (head = st;; head = tail) {
        double amt = strtod(head, &tail);

         /* No token found is end of string */
        if (head == tail)
            break;
        printf("%f0, amt);
    }
    exit(EXIT_SUCCESS);
}

_S_e_e _A_l_s_o
aattooff(), ddoouubbllee, eerrrrnnoo, lliibbcc, lliimmiittss.hh, ssttddlliibb.hh, ssttrrttooll(), ssttrrttoouull()
ANSI Standard, section 7.10.1.4

_N_o_t_e_s
ssttrrttoodd() ignores  initial white space  in the string pointed  to by _s_t_r_i_n_g;
white  space  is defined  as  being  all characters  so  recognized by  the
function iissssppaaccee().
