Hello again allmighty internet community: I'm a little bit stuck; I'm writting a program that will convert a number entered as a string into its correpsonding floating point representation. To do this I'm using the atof() function, which as I understan stands for ASCII to float. After watching the variables everything is ok except the converted variable which always gets an annoying 0.000000. Here's the code I've managed to cook so far:
As I was saying power represents the 10^n value according to the decimal position, but for some reason atof(data[i]-'0') isn't working. Any ideas? Thank you.Code:#include<conio.h> #include<stdio.h> #include<string.h> float Convert(char data[128]); void main(void){ char data[128]; float result; clrscr(); gets(data); result=Convert(data); clrscr(); printf("%f",result); getch(); } float Convert(char data[128]){ int i; float max,res,power,value; max=strlen(data); res=0.0; for (i=0;i<max;i++){ power=max-i-1; value=power*atof(data[i]-'0'); res=res+value; } return res; }