atoi.c

来自「自已写的一个嵌入式实时多任务抢占式操作系统。花了几个礼拜」· C语言 代码 · 共 46 行

C
46
字号
/*	Implementation module : atoi.c

	Copyright 1989 Diab Data AB, Sweden

	Description :
	Implemention of libc function
	int atoi(const char *);

	History :
	When	Who	What
	890307	teve	initial
*/

/**************	Imported modules ********************************/

#include <stdlib.h>
#include <ctype.h>

/**************	Local data, types, fns and macros ***************/



/**************	Implementation of exported functions ************/

int lib_atoi(const char *nptr)
{
	int i, c, neg = 0;
	
	while(isspace(c = *nptr++)) ;
	switch(c) {
	case '-':
		neg = 1;
		/* fall through */
	case '+':
		c = *nptr++;
		break;
	}
	i = 0;
	while(isdigit(c)) {
		i = i*10 + c - '0';
		c = *nptr++;
	}
	if (neg) return -i;
	return i;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?