/*************************************************************************
> File Name: atof.c
> Author: zhanglp
> Mail: ql.zhanglp@qq.com
> Created Time: 2014年09月28日 星期日 13时59分55秒
#include <ctype.h>
#include <stdlib.h>
double myAtof (const char *nptr)
{
double res_i = 0; // integer
double res_d = 1; // decimal
const char *p = nptr;
while ( isdigit (*p) ) {
res_i = res_i * 10 + (*p++ - '0');
}
if ( '.' == *p++ ) {
while ( isdigit (*p) ) {
res_i += (res_d /= 10) * (*p++ - '0');
}
}
return res_i;
}
int main (void)
{
const char *str = "143.43254354353425345432";
printf ("myAtof: %f\n", myAtof (str));
printf ("atof : %f\n", atof (str));
> File Name: atof.c
> Author: zhanglp
> Mail: ql.zhanglp@qq.com
> Created Time: 2014年09月28日 星期日 13时59分55秒
************************************************************************/
#include <stdio.h>#include <ctype.h>
#include <stdlib.h>
double myAtof (const char *nptr)
{
double res_i = 0; // integer
double res_d = 1; // decimal
const char *p = nptr;
while ( isdigit (*p) ) {
res_i = res_i * 10 + (*p++ - '0');
}
if ( '.' == *p++ ) {
while ( isdigit (*p) ) {
res_i += (res_d /= 10) * (*p++ - '0');
}
}
return res_i;
}
int main (void)
{
const char *str = "143.43254354353425345432";
printf ("myAtof: %f\n", myAtof (str));
printf ("atof : %f\n", atof (str));
return 0;
}
74.125.205.147