file-handling · intermediate · ~15 min
Read one line and strip the newline.
Implement int first_line(const char *path, char *out, int outsz) copying the first line (without the trailing newline) into out and returning its length, or -1 if the file can't be opened.
#include <stdio.h>
#include <string.h>
int first_line(const char *path, char *out, int outsz) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.