cybersecurity · intermediate · ~15 min · safe pentest lab
Count lines matching a status token.
Count the HTTP 404 responses in an access log — a spike often means someone is probing for hidden paths.
Implement int count_404s(const char *log) that returns how many lines contain the status token " 404 " (the number surrounded by spaces).
log: a NUL-terminated, newline-separated access-log string baked into the harness.Returns int: the number of lines containing " 404 ".
log: "GET /a 200 1\nGET /b 404 0\nGET /c 404 0\nGET /d 500 0\n"
count_404s(log) -> 2
4040 or a path like /404 does not count.A NUL-terminated newline-separated access-log string log.
An int: the number of lines containing the token " 404 ".
Match " 404 " with surrounding spaces. Static buffer only.
#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.