C examples for stdlib.h:atof
function
<cstdlib> <stdlib.h>
Convert string to double
double atof (const char* str);
Parameter | Description |
---|---|
str | C-string representation of a floating-point number. |
On success, the function returns the converted floating point number.
On error, the function returns zero (0.0).
#include <stdio.h> #include <stdlib.h> #include <math.h> int main ()/*from w ww. j av a 2 s . com*/ { double n,m; double pi=3.1415926535; char buffer[256]; printf ("Enter degrees: "); fgets (buffer,256,stdin); n = atof (buffer); m = sin (n*pi/180); printf ("The sine of %f degrees is %f\n" , n, m); return 0; }