C - AtoI: Convert a string of digits into its numeric equivalent

Share a big cow's artificial intelligence tutorial. Zero-based! Easy to understand! Funny and humorous! Hope you join the artificial intelligence team too! Please click http://www.captainbed.net

/*
 * AtoI: Convert a string of digits into its numeric equivalent.
 *
 * AtoI.c - by FreeMan
 */

int AtoI(char s[])
{
	int i, n;
	n = 0;
	for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i)
	{
		n = 10 * n + (s[i] - '0');
	}
	return n;
}

 

Guess you like

Origin blog.csdn.net/chimomo/article/details/114022367