Parse an integer · 解析整数
Parse an integer
Turn a string like "-123" into the number -123, by hand — the job atoi does. Read an optional leading - to fix the sign, then build the value digit by digit: each new digit means result = result * 10 + digit. A character converts to its digit value with c - '0'.
解析整数
把像 "-123" 这样的字符串手动转换成数字 -123 —— 也就是 atoi 做的事。先读取可选的前导 - 来确定符号,然后逐位构建数值:每来一个新数字就 result = result * 10 + 数字。一个字符可以用 c - '0' 转换成它的数字值。
Complete int parse_int(const char *s) that converts a string of digits (with an optional leading -) to its integer value, without using library functions like atoi. · 完成 int parse_int(const char *s),把一串数字(可带一个前导 -)转换成对应的整数值,不使用 atoi 等库函数。
Click Run to see the output here. · 点击“运行”查看此处输出。