troubleshooting Question

# SImple explain of the atof function ???

asked on
CC++
7 Comments1 Solution984 ViewsLast Modified:
Just a simple questions about atof function?
Why and when would you need a function that convert char to double value???
What is the purpose??
Can you explain to me the following 2 programs
give me some situations when such a function need to be use.
thanks

str = "  3336402735171707160320 ";

Is "333640273......"  being treated as a string and not a value?

* atof example: sine calculator */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
double n,m;
double pi=3.1415926535;
char sizeInput [256];
printf ( "Enter degrees: " );
gets_s ( sizeInput );       // WHY does this read in a degree value but declare as char to read up to 256 ???
n = atof ( sizeInput );
m = sin (n*pi/180);
printf ( "The sine of %f degrees is %f\n" , n, m );
return 0;
}

-----------------------------------------------------------------------------------------

// crt_atof.c
//
// This program shows how numbers stored as
// strings can be converted to numeric
// values using the atof function.

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
char    *str = NULL;
double  value = 0;

// An example of the atof function
// using leading and training spaces.
str = "  3336402735171707160320 ";
value = atof( str );
printf( "Function: atof( \"%s\" ) = %e\n", str, value );

// Another example of the atof function
// using the 'd' exponential formatting keyword.
str = "3.1412764583d210";
value = atof( str );
printf( "Function: atof( \"%s\" ) = %e\n", str, value );

// An example of the atof function
// using the 'e' exponential formatting keyword.
str = "  -2309.12E-15";
value = atof( str );
printf( "Function: atof( \"%s\" ) = %e\n", str, value );
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
###### Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.