Function name : strtod
Header file : <stdlib.h>
Function prototype : double strtod(char *s,char **ptr);
Function : Used to convert string to floating point number
Parameters : char *s is the string to be converted
char **ptr is a string pointer, used for error detection, and will terminate when encountering illegal characters; if ptr is not empty, the pointer to the character after the last character in the conversion will be stored at the location referenced by ptr.
Return value: Returns the converted floating point data. If no valid conversion is performed, zero (0.0) is returned.
Program example : Use this function to convert a string into a floating point number
#include<stdio.h>#include<stdlib.h>#include<time.h>intmain(void){char*endptr;chara[]=12345.6789;charb[]=1234.567qwer;charc[]=-232.23e4 ;printf(a=%lfn,strtod(a,NULL));printf(b=%lfn,strtod(b,&endptr));printf(endptr=%sn,endptr);printf(c =%lfn,strtod(c,NULL));return0;}
Running results
a=12345.678900b=1234.567000endptr=qwerc=-2322300.000000