写一个atoi函数

写一个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;
	}


猜你喜欢

转载自blog.csdn.net/u012824097/article/details/60322889