一个atoi的实现函数
来源:互联网 发布:微信公众平台框架 java 编辑:程序博客网 时间:2024/06/06 20:21
实现一:
#include <assert.h>
int my_atoi(const char * str)
{
assert(str);
int ret = 0;
int flag = 1;
if(*str == '-'){
flag = -1;
str ++;
}else if(*str == '+'){
str++;
}
while(*str){
unsigned int ch = str[len] - '0';
assert(ch<=9 && ch >=0);
ret = ret * 10 + ch;
}
return ret * flag;
}
int my_atoi(const char * str)
{
assert(str);
int ret = 0;
int flag = 1;
if(*str == '-'){
flag = -1;
str ++;
}else if(*str == '+'){
str++;
}
while(*str){
unsigned int ch = str[len] - '0';
assert(ch<=9 && ch >=0);
ret = ret * 10 + ch;
}
return ret * flag;
}
实现二:
int myatoi(const char* str)
{
int i=0,j=0,k=1;
if(str[j] == '-') {
k = -1;
j++;
}
if(str[j] == '+') {
j++;
}
while(!isalpha(str[j]) && j<strlen(str))
{
i = i*10+ (str[j] - '0');
j++;
isalpha()函数说明:
原型:extern int isalpha(int c);
用法:#include <ctype.h>
功能:判断字符c是否为英文字母
说明:当c为英文字母a-z或A-Z时,返回非零值,否则返回零。
- 一个atoi的实现函数
- atoi的一个实现
- atoi函数的实现
- atoi()函数的实现
- atoi()函数的实现
- atoi函数的实现
- atoi函数的实现
- atoi函数的实现
- atoi函数的实现
- atoi函数的实现
- atoi函数的实现
- atoi()函数的实现
- atoi()函数的实现
- atoi()函数的实现
- atoi函数的实现
- atoi()函数的实现
- atoi函数的实现
- atoi()函数的实现
- 关于base标签的使用
- SQL 语句使用二
- Janus WinForms Controls Suite V2 for VS2003
- 响应按钮的事件
- jsp错误-剪切
- 一个atoi的实现函数
- 警惕UNIX下的LD_PRELOAD环境变量
- 写 Java 程序最容易犯的 21 种错误实例分析
- 禁止DataGridView点击表头进行排序(WinForm)
- [DB][Oracle]如何用一个SQL文实现Insert/Update/Delete和--MERGE命令详解
- eclipse3.2.1+myeclipse+ejb3.0(如何再eclipse3.2下做ejb3.0的开发)
- 学习QTP笔记2
- 什么是TTL
- Booksir路线:先成材,再成功,警察到书生的传奇(转载)