I wrote this to covert the string to double, but I'm having problem fixing the loop so that it goes through all the digits. when I run this it only converts the first which is -42.40000 and stops.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
main(){
double result, convert(char s[]);
char arr[]="-42.4 5 34 66";
result=convert(arr);
printf("%f", result);
getchar();
}
double convert(char s[])
{
double val, power;
int i, sign,pos,c;
for (i =0; isspace(s[i]); i++) ;
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-')
i++;
for (val = 0.0; isdigit(s[i]); i++)
val = 10.0 * val + (s[i] - '0');
if (s[i] == '.')
i++;
for (power = 1.0; isdigit(s[i]); i++)
{
val = 10.0 * val + (s[i] - '0');
power *= 10;
}
return sign * val / power;
}