file-handling · intermediate · ~15 min

First error line number

Track a line counter while scanning.

Challenge

Implement int first_error_line(const char *log) returning the 1-based line number of the first line containing "ERROR", or -1 if there is none.

Starter code

#include <string.h>

int first_error_line(const char *log) {
    /* TODO */
    return -1;
}

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