Parse an integer · Analizar un entero
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'.
Analizar un número entero
Convierte una cadena como "-123" en el número -123, tal como lo haría la función atoi. Lee un signo - opcional al inicio para determinar el signo, luego construye el valor dígito por dígito: cada nuevo dígito significa result = result * 10 + digit. Un carácter se convierte a su valor numérico mediante 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. · Completa int parse_int(const char *s) que convierte una cadena de dígitos (con un opcional - inicial) a su valor entero, sin usar funciones de biblioteca como atoi.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.