long long atoll(const char *p)
{
long long n;
int c, neg = 0;
unsigned char *up = (unsigned char *)p;
if (!isdigit(c = *up)) {
while (isspace(c))
c = *++up;
switch (c) {
case '-':
neg++;
/* FALLTHROUGH */
case '+':
c = *++up;
}
if (!isdigit(c))
return (0);
}
for (n = '0' - c; isdigit(c = *++up); ) {
n *= 10; /* two steps to avoid unnecessary overflow */
n += '0' - c; /* accum neg to avoid surprises at MAX */
}
return (neg ? n : -n);
}C/C++ atoll函数实现
最新推荐文章于 2024-10-04 13:34:58 发布
本文介绍了一个C语言中的自定义函数longlongatoll,该函数用于将字符串转换为long long类型的整数。文章详细展示了函数的工作原理,包括如何处理正负号、空格以及非数字字符等特殊情况。

1261

被折叠的 条评论
为什么被折叠?



