#include <stdio.h>
#include <ctype.h>
/*将字符串转换为双精度浮点数*/
double atoi(char *str);
int main()
{
char str[] = " 34.45";
printf("%.4g\n", atoi(str));
return 0;
}
double atoi(char *str)
{
double sum = 0, flag = 1;
int sign = 0;//符号标记
while(*str == ' ' || *str == '\t')
str++;
sign = (*str == '-')? -1: 1;
printf("%d\n",sign);
while(isdigit(*str)){
sum = sum * 10 + (*str - '0');
str++;
}
if(*str == '.'){
str++;
while(isdigit(*str)){
sum = sum * 10.0 + (*str - '0');
flag *= 10.0;
str++;
}
sum = sign * sum /flag;
}
return sum;
}