cybersecurity · intermediate · ~15 min · safe pentest lab
Extract the numeric status code from an HTTP response line.
Reading a banner from a local service often means parsing its first response line. For HTTP, extract the status code:
int parse_http_status(const char *resp);
Return the 3-digit status code from a line like "HTTP/1.1 200 OK", or −1 if the line does not start with "HTTP/" or has no valid 3-digit code.
A NUL-terminated response line.
The status code, or −1.
The line must begin with HTTP/. The code is the first space-delimited token and must be exactly three digits.
#include <stddef.h>
/* A local service replied with an HTTP status line like "HTTP/1.1 200 OK".
Return the 3-digit status code (100..599 range not enforced beyond 3 digits),
or -1 if the line does not start with "HTTP/" or has no valid 3-digit code. */
int parse_http_status(const char *resp){ (void)resp; return -1; }
Not checking the HTTP/ prefix; reading fewer/more than three digits; accepting a code not delimited by a space/CR/LF/end.
"HTTP/1.1 200 OK"→200; "HTTP/1.1 2 OK" and "200 OK" are invalid; the code may end the string.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.