cybersecurity · intermediate · ~15 min · safe pentest lab

Count 404 responses

Count lines matching a status token.

Challenge

Count the HTTP 404 responses in an access log — a spike often means someone is probing for hidden paths.

Task

Implement int count_404s(const char *log) that returns how many lines contain the status token " 404 " (the number surrounded by spaces).

Input

  • log: a NUL-terminated, newline-separated access-log string baked into the harness.

Output

Returns int: the number of lines containing " 404 ".

Example

log: "GET /a 200 1\nGET /b 404 0\nGET /c 404 0\nGET /d 500 0\n"
count_404s(log)   ->   2

Edge cases

  • A log with no 404 lines returns 0.
  • Match the status with surrounding spaces so 4040 or a path like /404 does not count.

Rules

  • Static buffer only — no real log-file access.

Input format

A NUL-terminated newline-separated access-log string log.

Output format

An int: the number of lines containing the token " 404 ".

Constraints

Match " 404 " with surrounding spaces. Static buffer only.

Starter code

#include <string.h>

int count_404s(const char *log) {
    /* TODO */
    return 0;
}

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