networking · intermediate · ~15 min

Parse the status code

Extract the status code from a response.

Challenge

Implement int parse_status_code(const char *resp) returning the numeric status from a response status line like HTTP/1.1 200 OK, or -1 if it doesn't start with HTTP/.

Starter code

#include <string.h>
#include <stdlib.h>

int parse_status_code(const char *resp) {
    /* TODO */
    return -1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.