C Library Function - strtod()
Description
C Library Function **double strtod(const char *str, char endptr) Converts the string pointed to by the argument str converts the string pointed to by endptr to a floating-point number (of type double). If
Declaration
Below is the declaration of the strtod() function.
double strtod(const char *str, char **endptr)
Parameters
- str -- The string to be converted to a double-precision floating-point number.
- endptr -- A reference to an object of type char*, whose value is set by the function to str the next character after the numeric value in
Return Value
This function returns the converted double-precision floating-point number; if no valid conversion was performed, it returns zero (0.0).
Example
The following example demonstrates the use of the strtod() function.
#include
#include
int main()
{
char str[30] = "20.30300 This is test";
char *ptr;
double ret;
ret = strtod(str, &ptr);
printf("数字(double)是 %lf\n", ret);
printf("字符串部分是 |%s|", ptr);
return(0);
}
Let's compile and run the above program, which will produce the following result:
数字(double)是 20.303000
字符串部分是 | This is test|
C Standard Library -