cybersecurity · intermediate · ~15 min · safe pentest lab
Count runs of printable bytes of a minimum length — the heart of the `strings` tool.
The strings utility surfaces embedded text in a binary. Implement its counter:
int count_printable_runs(const unsigned char *buf, size_t n, int minlen);
Count maximal runs of printable ASCII (0x20-0x7e) whose length is at least minlen.
buf of n bytes and a minlen (>=1; values <1 are treated as 1).
Number of qualifying runs.
Non-printable bytes end a run.
#include <stddef.h>
/* Count runs of printable ASCII (0x20..0x7e) whose length is >= minlen (>=1). */
int count_printable_runs(const unsigned char *buf, size_t n, int minlen){ (void)buf;(void)n;(void)minlen; return 0; }
Forgetting to count the final run after the loop; counting runs shorter than minlen.
A run at the very end of the buffer still counts; empty buffer returns 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.