This shows you the differences between two versions of the page.
— |
c:stdlib.h:strtod [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ===== strtod ===== | ||
+ | <code c> | ||
+ | #include <stdlib.h> | ||
+ | double strtod(const char *str, char **endptr); | ||
+ | </code> | ||
+ | strtod converts a string into a double variable | ||
+ | |||
+ | ===== strtod c code example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * strtod example code | ||
+ | * http://code-reference.com/c/stdlib.h/strtod | ||
+ | */ | ||
+ | #include <stdio.h> | ||
+ | #include <stdlib.h> | ||
+ | |||
+ | int main ( void ) | ||
+ | { | ||
+ | char string[] ="2040 strtod string 5"; | ||
+ | char *endptr; | ||
+ | double number; | ||
+ | |||
+ | number = strtod(string, &endptr); | ||
+ | printf("String is %s\n",string); | ||
+ | printf("Double is %f\n", number); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== Output ==== | ||
+ | |||
+ | user@host:~$ ./strtod | ||
+ | String is 2040 strtod string 5 | ||
+ | Double is 2040.000000 | ||
+ | |||