The function strtod () in C
The double strtod function (const char * str, char ** endptr) in Standard C library converts a string pointed to by parameter str to a floating point number (type double).
The double strtod function (const char * str, char ** endptr) in Standard C library converts a string pointed to by parameter str to a floating point number (type double). If endptr is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.
Declaring the function strtod () in C
Below is the declaration for strtod () function in C:
double strtod ( const char * str , char ** endptr )
Parameters
str - This is the value to be converted into a string.
endptr - This is a reference to a allocated object of type char *, whose value is set by the function to the next character in str after the numeric value.
Returns the value
This function returns the floating point number that was converted as a double value. If not, the function returns 0.0.
For example
The following program C illustrates the usage of the strtod () function in C:
#include #include int main () { char str [ 30 ] = "21.32301 Hoc C tai QTM" ; char * ptr ; double ret ; ret = strtod ( str , & ptr ); printf ( "Phan gia tri (double) la: %lfn" , ret ); printf ( "Phan chuoi la: |%s|" , ptr ); return ( 0 ); } Compile and run the above C program to see the results.
According to Tutorialspoint
Previous lesson: Atol () function in C
Next lesson: Function strtol () in C
Discover more
C program operation string in C parameter in CShare by
Kareem WintersYou should read it
- Function strtoul () in C
- Function strtol () in C
- Atof () function in C
- The memchr () function in C
- The function gets () in C
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- Function strtol () in C
- Function strtoul () in C
- Calloc () function in C