atoi实现
来源:互联网 发布:重庆少儿编程 编辑:程序博客网 时间:2024/06/06 20:24
对于关键字_Bool
我们都知道在c中c89是没有bool类型的,c99引用了一个_Bool关键字代表布尔类型。其中当给该关键字赋值非0时,该关键字值为1,给该关键字赋值为0时,该关键字值为0。这也符合c语言之前对于逻辑判断的特性,对于0为假,非0值代表真。
bool宏
在c99后引用了_Bool关键字后,在stdbool.h头文件中定义了三个宏代表bool类型,第一个宏bool,第二个宏True,第三个宏false为了向c++兼容。
atoi代码
#include<stdio.h>#include <stdlib.h>enum status{ Valid = 0, InValid, ERange,};int my_errno = Valid;int my_atoi(const char* p){ if (p == NULL) { my_errno = InValid; return 0; } while (isspace(*p)) ++p;//处理空格 _Bool minus = 0; unsigned nums = 0; if (*p == '+'||*p=='-'||*p>='0'||*p<='9') { if (*p == '+') ++p; else if (*p == '-') { ++p; minus = 1; } else { while ('0' <= *p && *p <= '9') { nums = nums * 10 + (*p - '0'); ++p; if (minus == 0 && nums>0x7fffffff || minus == 1 && nums<0x80000000) goto Rang; } } nums = minus ? nums : -1 * nums; } else{ goto Inval; } return nums;Inval: my_errno = InValid; return 0;Rang: my_errno = ERange; return 0;}
阅读全文
0 0
- LeetCode(atoi)实现atoi
- atoi实现
- atoi实现
- atoi 实现
- 实现atoi
- atoi实现
- 实现atoi
- atoi实现
- atoi实现
- atoi实现
- atoi实现
- atoi实现
- 自己实现atoi系列(atoi函数)
- atoi及itoa 实现
- atoi函数实现
- atoi,itoa函数实现
- 自己实现atoi系列
- atoi,itoa实现
- 时间队列容器,包含类用法
- 第二章作业
- 【面试】秒杀设计
- 2017/8/20
- 宏观上把握DbUtils
- atoi实现
- leveldb
- 引入font字体出现方框框的问题
- 【C#机房重构】七层登录详解
- D
- 单点登录
- POJ 1322 dp
- IGMP:Internet组管理协议
- java数据类型的种类以及存放的位置