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이 수행하는 작업입니다. 부호를 고정하기 위해 선택적 선두 -을 읽고, 각 새로운 digit가 result = result * 10 + digit을 의미하도록 digit별로 값을 구성합니다. 문자는 c - '0'을 통해 해당 digit 값으로 변환됩니다.
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.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.