Parse an integer · Analyser un entier
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'.
Parser un entier
Transformez une chaîne comme "-123" en le nombre -123, à la main — le travail que fait atoi. Lisez un - optionnel au début pour fixer le signe, puis construisez la valeur chiffre par chiffre : chaque nouveau chiffre signifie result = result * 10 + digit. Un caractère se convertit en sa valeur numérique avec 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. · Complétez int parse_int(const char *s) qui convertit une chaîne de chiffres (avec un - optionnel au début) en sa valeur entière, sans utiliser de fonctions de bibliothèque comme atoi.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.