strtod() function in c

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 in 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.

String() Page

Output

	The number is:40.300000 and string is:   scholarsoul 
Output for strtod in c programming

People also ask for

What is the difference between strtod and atof in c?

strtod is robust. atof() is used for compatibility.


Leave a Comment