C语言模拟实现atoi函数
来源:互联网 发布:mac怎么卸载驱动 编辑:程序博客网 时间:2024/05/17 03:08
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <assert.h>enum{INVALUE,VALUE};int my_atoi(char *str){int tmp = 0;int flag = 1;int num = 0;//空指针assert(str != NULL); //空字符串if (*str == '\0'){return 0;}//空格处理while (isspace(*str)){str++;}//+ -if (*str == '-'){str++;flag = -1;}//异常字符处理while (isdigit(*str)){ tmp = tmp * 10 + (*str -'0')*flag;str++;//溢出处理if ((tmp > INT_MAX) || (tmp < INT_MIN)){num = INVALUE;}else{num = VALUE;}}return tmp;}int main(){int a = my_atoi("");int b = my_atoi(" ");int c = my_atoi("1234");int d = my_atoi("-1234");int e = my_atoi(" 1234");int f = my_atoi("iii1234");int g = my_atoi("122344443433232323234");int h = my_atoi("-12333333333333333333");printf("%d\n", a);printf("%d\n", b);printf("%d\n", c);printf("%d\n", d);printf("%d\n", e);printf("%d\n", f);printf("%d\n", g);printf("%d\n", h);system("pause:");return 0;}
输出结果:
阅读全文
0 0
- C语言模拟实现atoi函数
- C语言模拟实现atoi函数
- 【c语言】 模拟实现库函数的atoi函数
- C语言实现atoi函数
- Atoi函数C语言实现
- 模拟实现C语言中的库函数atoi
- C语言模拟实现库函数atoi
- [c语言] 模拟实现c语言库函数atoi
- 模拟实现atoi函数
- 模拟实现atoi函数
- 模拟实现atoi函数
- 模拟实现atoi函数
- 模拟实现atoi函数
- 模拟实现atoi函数
- 模拟实现atoi函数
- 模拟实现atoi函数
- 模拟实现atoi函数
- C语言atoi函数的实现
- 前端面试题 ----- HTML语义化 link和@import的区别
- PAT乙级 1049. 数列的片段和(20)--数学问题
- Tengine健康检查模块配置
- 二叉树面试题之二叉树镜像
- Java NIO原理图文分析及代码实现
- C语言模拟实现atoi函数
- PAT乙级 1050. 螺旋矩阵(25)
- angularjs知识点四指令
- 文章标题 POJ 1789 :Truck History (最小生成树+prim)
- spring整合webService(客户端)
- 我的小小学习笔记(1)之C语言--sizeof&strlen(1)
- RollViewPager图片轮播效果开源框架的使用
- Unknown column 'abc' in 'field lis
- 获取设备信息的工具类