?? strtol.c
字號:
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
long strtol(CONST char *s, char **end, int base)
{
int uminus;
int endchar;
int enddigit;
long oldval;
long val = 0;
while (isspace(*s))
s++;
if (*s == 0 || !(base == 0 || (1 < base && base <= 36)))
{
if (end)
*end = (char *)s;
return 0;
}
uminus = 0;
if (*s == '-')
{
s++;
uminus = 1;
}
else if (*s == '+')
s++;
if (s[0] == '0' && (s[1] == 'X' || s[1] == 'x') &&
(base == 16 || base == 0))
{
base = 16;
s += 2;
}
if (base == 0)
base = (*s == '0') ? 8 : 10;
enddigit = (base >= 10) ? '9': base - 1 + '0';
if (base > 10)
endchar = base - 11 + 'a';
for ( ; *s; s++)
{
int c;
if (isdigit(*s) && *s <= enddigit)
c = *s - '0';
else if (base > 10 && (c = tolower(*s)) >= 'a' && c <= endchar)
c = c - 'a' + 10;
else
break;
oldval = val;
val = val * base + c;
if (val < oldval)
{
errno = ERANGE;
return (uminus) ? LONG_MIN : LONG_MAX;
}
}
if (end)
*end = (char *)s;
return (uminus) ? -val : val;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -