?? strtol.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 + -