file-handling · intermediate · ~15 min

Count lines at a level

Iterate lines and test each for a token.

Challenge

A log is a multi-line string. Implement int count_level(const char *log, const char *level) returning how many lines contain level as a substring (e.g. "ERROR").

Starter code

#include <string.h>

int count_level(const char *log, const char *level) {
    /* TODO */
    return 0;
}

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