HI I have recently started learning to use C and have been having a weird experience using atof, it never returns the correct value for me.
I created a small program to test this and the values it returns are really strange. I have intentionally created the functions in different files because the real program I am working which requires use of atof is set up this way.
For example if I enter 1 into the program it will return the value entered as 0, 12 will give me a value of 524288.00 ????
I thought it might have something to do with the data type so I switched from double to float to no avail.
Code:
#include <stdio.h>
float read_input(){
char sinput[256];
gets(sinput);
float dinput;
dinput = atof( sinput );
return dinput; }
Code:
#include "read_input.c"
#include <stdio.h>
main(){
float lower;
printf("please enter a value");
lower=read_input();
printf("you have entered %f\n",lower); }
Any help in understanding this would be appreciated.