Atof() - C library function Program

Declaration :

double atof(const char *str)

Explanation :

PurposeThe C library function double atof(const char *str) converts the string argument str to a floating-point number (type double).
Parameters str ===> This is the string having the representation of a floating-point number.
Return ValueThis function returns the converted floating point number as a double value. If no valid conversion could be performed it returns zero (0.0).
Exception

C Program : Example

The following example shows the usage of atof() function.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
   float value;
   char str[20];
   strcpy(str, "12.34");
   value= atof(str);
   printf("\nString equivalent value of %s = %f", str, value);
   strcpy(str, "pritesh");
   value= atoi(str);
   printf("\nString equivalent value of %s = %f", str, value);
   return(0);
}