字符串引号的结尾默认会有一个\0的字符,所以是9个。
不知道你这个问题是否已经解决, 如果还没有解决的话:atoi实现原理:
isspace(int x)
{
if(x==' '||x=='\t'||x=='\n'||x=='\f'||x=='\b'||x=='\r')
return 1;
else
return 0;
}
isdigit(int x)
{
if(x<='9'&&x>='0')
return 1;
else
return 0;
}
int atoi(const char *nptr)
{
int c;
int total;
int sign;
while ( isspace((int)(unsigned char)*nptr) )
++nptr;
c = (int)(unsigned char)*nptr++;
sign = c;
if (c == '-' || c == '+')
c = (int)(unsigned char)*nptr++;
total = 0;
while (isdigit(c)) {
total = 10 * total + (c - '0');
c = (int)(unsigned char)*nptr++;
}
if (sign == '-')
return -total;
else
return total;
}
ASCII表示的字符有128个,所以不存在最高位的讨论,针对最高位如何变换存储,前面的博客《C语言的位操作》有分析,各个转义字符可以百度。
一句话:就是软件构造出转字符流转字节流之前的算法