首页 > 学院 > 开发设计 > 正文

写一个atoi函数

2019-11-06 07:47:23
字体:
来源:转载
供稿:网友

写一个Atoi函数,实现字符串转换成整型数字

int MyAtoi(const char *p)	{		int result = 0;		int flag = 1;		if (*p == '-' || *p == '+' || (*p >= '0'&&*p <= '9'))		{			if (*p == '-')			{				flag = -1;				p++;			}			else if (*p == '+')			{				p++;			}			while (*p >= '0' && *p <= '9')			{				result = 10 * result + *p++ - '0';			}		}		return flag*result;	}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表