str系列函数的实现
来源:互联网 发布:mac app cleaner 编辑:程序博客网 时间:2024/05/16 08:22
//atoi#include <stdio.h>#include <assert.h>#include <ctype.h>int my_atoi(char *pstr){ assert(pstr != NULL); int ret_int = 0; int sign = 1; while(isspace(*pstr)){ pstr++; } if(*pstr == '-' || *pstr == '+' || (*pstr > '0' && *pstr < '9')){ if(*pstr == '-' || *pstr == '+'){ if(*pstr == '-'){ sign = -1; } pstr++; } if(!(*pstr >= '0' && *pstr <= '9')){ printf("the str is not ok\n"); return -1; } while(*pstr >= '0' && *pstr <= '9'){ ret_int = ret_int * 10 + *pstr - '0'; pstr++; } if(*pstr != '\0'){ printf("the str is not ok\n"); return -1; } ret_int = sign * ret_int; }else{ printf("the str is not ok\n"); return -1; } return ret_int;}int main(int argc, char **args){ char a[] = "-a100a"; char b[] = "500b"; int aa = my_atoi(a); int bb = my_atoi(b); printf("%d %d\n", aa, bb); return 0;}
0 0
- str系列函数的实现
- 看看str系列函数的实现 一
- str系列函数的用法和实现代码
- str相关的函数实现
- str系列函数
- C系列函数原型之-StrStr(char *str,char *subStr)的实现
- str-...的函数的模拟实现学习
- 模拟实现strcpy,strcmp,等str~系列函数
- 又一波str函数的模拟实现
- 实现str基本函数
- C语言str函数系列
- C语言str函数系列
- C语言str函数系列
- C语言str函数系列
- C语言str系列函数
- 编写函数实现str函数
- str功能的实现
- 自定义实现类似Java的Integer.parseInt(String str)函数
- MOS管开关等效电路
- 测试度量--测试工作量估算
- 语言基础(关于字符串相关的getchar、getline之类)
- MySQL 删除表的所有数据
- CANDENCE 焊盘封装心得(欢迎拍砖 都来拍砖)
- str系列函数的实现
- ACDream 1119 瑶瑶的动感光波(加强版)背包
- java 读文件大全
- html游戏引擎,createJs框架
- Task与Activity详解
- 颜色代码大全
- jQuery介绍
- JSP九大内置对象详细分析
- edx-platform的学习资料整理