C语言实现数字的字符串形式转整形的数字的功能

/* From: http://fossies.org/dox/musl-1.0.5/atoi_8c_source.html */
//drivers/wifi/host/platform/actions_ats3503/porting.h
#define isdigit(c)           in_range(c, '0', '9')
#define isspace(c)           (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
//source/stdlib/atoi.c
int atoi(const char *s)
{
	int n = 0;
	int neg = 0;

	while (isspace(*s)) {
		s++;
	}
	switch (*s) {
	case '-':
		neg = 1;
		s++;
		break;	/* artifact to quiet coverity warning */
	case '+':
		s++;
	}
	/* Compute n as a negative number to avoid overflow on INT_MIN */
	while (isdigit(*s)) {
		n = 10*n - (*s++ - '0');
	}
	return neg ? n : -n;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值