basics · intermediate · ~15 min
Turn text into a number — what scanf does under the hood.
Instead of reading stdin, parse from a string. Implement int parse_int(const char *s, int *out) that parses an optional leading '-' then decimal digits, stores the value in *out, and returns 1 on success or 0 if s is not a valid integer.
int parse_int(const char *s, int *out) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.