⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strtol.c

📁 微操作系统(c++)
💻 C
字号:
/*  * Copyright (c) 1995-1994 The University of Utah and * the Computer Systems Laboratory at the University of Utah (CSL). * All rights reserved. * * Permission to use, copy, modify and distribute this software is hereby * granted provided that (1) source code retains these copyright, permission, * and disclaimer notices, and (2) redistributions including binaries * reproduce the notices in supporting documentation, and (3) all advertising * materials mentioning features or use of this software display the following * acknowledgement: ``This product includes software developed by the * Computer Systems Laboratory at the University of Utah.'' * * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * CSL requests users of this software to return to csl-dist@cs.utah.edu any * improvements that they make and grant CSL redistribution rights. */#include <ctype.h>#include <string.h>long strtol(const char *p, char **out_p, int base){	long v = 0;	int is_neg = 0;	while (isspace(*p))		p++;	if (*p == '-')		is_neg = 1, p++;	else if (*p == '+')		is_neg = 0;	if (((base == 16) || (base == 0)) &&	    ((*p == '0') && ((p[1] == 'x') || (p[1] == 'X'))))	{		p += 2;		base = 16;	}	if (base == 0)	{		if (*p == '0')			base = 8;		else			base = 10;	}	while (1)	{		char c = *p;		if ((c >= '0') && (c <= '9') && (c - '0' < base))			v = (v * base) + (c - '0');		else if ((c >= 'a') && (c <= 'z') && (c - 'a' + 10 < base))			v = (v * base) + (c - 'a' + 10);		else if ((c >= 'A') && (c <= 'Z') && (c - 'A' + 10 < base))			v = (v * base) + (c - 'A' + 10);		else			break;		p++;	}	if (is_neg)		v = -v;	if (out_p) *out_p = (char*)p;	return v;}

⌨️ 快捷键说明

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