file-handling · beginner · ~15 min

Count lines from a string buffer

Streaming character classification without I/O.

Challenge

Implement size_t buffer_line_count(const char *buf) that counts newline characters in buf. Useful when you've already read a file into memory.

Starter code

#include <stddef.h>
size_t buffer_line_count(const char *buf) { /* TODO */ return 0; }

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