networking · intermediate · ~15 min
Robust string parsing, fail-fast on malformed input.
Implement int parse_status_line(const char *line, int *out_status) that parses lines like HTTP/1.1 200 OK\r\n and writes the numeric status into *out_status. Return 0 on success, -1 on malformed input.
Pure parser — no real network call.
#include <stddef.h>
int parse_status_line(const char *line, int *out_status) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.