atof函数的实现
来源:互联网 发布:雄3导弹知乎 编辑:程序博客网 时间:2024/05/18 03:12
/*************************************************************************
> 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
0 0
- atof函数的实现
- atof函数的实现
- C 标准库 atof 函数的实现
- 自己实现的atio()和atof()函数
- atof()函数实现
- atof & aoti 函数实现
- java 实现atof函数
- atof函数的编写
- atof的实现
- atof的简单实现
- atof函数实现代码,原理
- C函数的实现(strcpy,atoi,atof,itoa,reverse)
- 用c语言实现一个自己的atof()函数
- 【c语言】模拟实现库函数的atof函数
- 从0开始<十>:atof 函数的简单实现
- atof函数的实现 查找最长数字子串
- C/C++ atoi、atof与itoa函数的实现
- atoi函数和atof函数实现
- Objective-C基础回顾 1. 复制--NSCopying
- kafka
- iphone-命令行编译之--xcodebuild
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
- centos yum 库更新
- atof函数的实现
- 30多年程序员生涯经验总结
- 实现XML的简单动态配置
- Atlas源码学习(五)
- httpclient测试例子
- hdu 5045 Contest(状态压缩DP)
- 精益生产管理有哪些内涵
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)
- java判断字符串是否为空的方法总结