networking · intermediate · ~15 min

Parse an HTTP status line

Robust string parsing, fail-fast on malformed input.

Challenge

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.

Starter code

#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.