cybersecurity · beginner · ~20 min
Strict prefix matching.
Given a base log name name (e.g. app.log) and a candidate filename candidate, implement int is_rotated_log(const char *name, const char *candidate) that returns 1 iff candidate matches name exactly OR starts with name + "." followed by at least one character. (E.g. app.log, app.log.1, app.log.2024-01-15.gz all match; app.log. does not.)
A common pattern in incident response: scan a directory listing for rotated log files (app.log.1, app.log.2024-01-15, etc.) so you can pull the right archive. Building a simple matcher teaches glob-like patterns the disciplined way.
Two null-terminated strings.
0 or 1.
No regex.
int is_rotated_log(const char *name, const char *candidate) { /* TODO */ return 0; }
Treating app.log2 as a rotation (must require literal . between name and suffix); accepting app.log. with no trailing chars (degenerate case).
Exact match. Empty candidate. Candidate shorter than name.
O(strlen).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.