C - ItoA: Convert a number to a character string (the inverse of AtoI)

分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net

/*
 * ItoA: Convert a number to a character string (the inverse of AtoI).
 *
 * ItoA.c - by FreeMan
 */

void ItoA(int n, char s[])
{
	int i, sign;
	if ((sign = n) < 0) /* Record sign */
	{
		n = -n; /* Make n positive */
	}
	i = 0;
	do { /* Generate digits in reverse order */
		s[i++] = n % 10 + '0'; /* Get next digit */
	} while ((n /= 10) > 0); /* Delete it */
	if (sign < 0)
	{
		s[i++] = '-';
	}
	s[i] = '\0';
	Reverse(s);
}

 

相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页