偶尔会遇到的,记录一下。
/* 字符串转long long */ 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); }
原文:https://www.cnblogs.com/nxopen2018/p/14465772.html