file-handling · intermediate · ~15 min
Iterate a text file line by line with fgets.
Implement int count_file_lines(const char *path) returning the number of lines (use fgets), or -1 if the file can't be opened.
#include <stdio.h>
int count_file_lines(const char *path) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.