#include <ctype.h>
/*简单的字符串转浮点型函数*/
double atof(char s[]);
int main()
{
return 0;
}
double atof(char s[])
{
double val, power;
int i, sign;
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;
}
书上例子-简单的atof函数
最新推荐文章于 2022-12-10 15:13:07 发布