Mega Code Archive

 
Categories / C / Code Snippets
 

Convert string to double how to use atof

#include <stdio.h> #include <math.h> int main () { double j, k; double pi = 3.1415926535; char str[256]; printf ( "Enter degrees: " ); gets ( str ); j = atof ( str ); k = sin (j * pi / 180); printf ( "sine of %f degrees = %f\n" , j, k ); return 0; }