Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>strtod() convert string to double</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
strtod()                 Convert String to Double

 #include   <stdlib.h>

 double     strtod(nptr,endptr);
 char       *nptr;                       Pointer to string
 char       **endptr;                    Pointer to end of scan

    strtod() converts a string to a double value.  The string is a
    sequence of characters that can be interpreted as a double value. The
    string must match this sequence:

        [whitespace] [sign] [digits] [.digits] [{d|D|e|E} [sign] digits]

    strtod() stops reading the string at the first character that cannot
    be recognized as part of a double value.  If 'endptr' is not NULL, it
    points to the character that stopped the scan.

    Returns:    The value of the floating-point number.  +/-HUGE is
                returned when the representation would cause an overflow
                or underflow. On error, ERRNO is set to ERANGE.

  -------------------------------- Example ---------------------------------

    The following statements convert two strings into doubles, add them
    together, and print the total.

           #include <stdlib.h>
           #include <stdio.h>

           double total;
           double dubl1, dubl2;
           char *str1 = "982.50 dollars", *str2 = "540.00 dollars";
           char *txt1, *txt2
           main()
           {
           /* The space before "dollars" will stop the scanning of string. */
               dubl1 = strtod(str1,&txt1);
               dubl2 = strtod(str2,&txt2);
               total = dubl1 + dubl2;
               printf("TOTAL: %.2f ",total);
            }

See Also: strtol() atof() atol()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson