Table of contents
What is strtod() in c?
strtod() converts the given string to floating point value.
It sets a pointer to point to the first character of the string otherwise it sets the pointer to NULL.
It is defined under stdlib.h header file.
Prototype
double strtod(const char* string,char **endpointer);
Return value
strtod() function returns converted floating point number as a double value else zero is returned.
Example program for strtod() in c
#include<stdio.h>
#include<stdlib.h>
int main()
{
char string[30]=" 40.30 scholarsoul";
char *pointer;
double res;
res=strtod(string,&pointer);
printf("The number is:%lf and string is:%s \n",res,pointer);
return 0;
}
Code explanation
strtod() converts the given string to floating point value.
Output
The number is:40.300000 and string is: scholarsoul
People also ask for
What is the difference between strtod and atof in c?
strtod is robust. atof() is used for compatibility.
People also read
strcat()
function in c.strlen()
function in c.strncat()
function in c.strcmp()
function in c.- String functions.
- strtol() in function in c.