Parse an integer · Analisar um inteiro
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'.
Parseie um inteiro
Transforme uma string como "-123" no número -123, manualmente — a função atoi faz isso. Leia um opcional leading - para ajustar o sinal, depois construa o valor dígito por dígito: cada novo dígito significa result = result * 10 + digit. Um caractere converte para seu valor numérico com 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. · Complete int parse_int(const char *s) que converte uma string de dígitos (com um sinal opcional à esquerda -) em seu valor inteiro, sem usar funções de biblioteca como atoi.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.