basics · intermediate · ~15 min
Tokenise a small input line.
Parse a line containing two space-separated non-negative integers.
Implement int parse_pair(const char *s, int *a, int *b) that parses two non-negative integers from s, separated by a single space (e.g. "12 34"). On success, store them in *a and *b and return 1. Return 0 if the format is wrong (wrong separator, negative numbers, missing values, or trailing junk). No main — the grader calls it.
A NUL-terminated string s, and two pointers a and b for the results.
Returns 1 on success (with *a and *b set); 0 on any invalid input.
parse_pair("12 34", &a, &b) -> 1, a == 12, b == 34
parse_pair("0 7", &a, &b) -> 1, a == 0, b == 7
parse_pair("12-34", &a, &b) -> 0 (wrong separator)
A NUL-terminated string s, and two int pointers a and b.
1 on success (with *a and *b set); 0 on invalid input.
Two non-negative ints separated by a single space; reject anything else.
int parse_pair(const char *s, int *a, int *b) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.