file-handling · intermediate · ~15 min
Use fread to pull raw bytes.
Implement int read_first_bytes(const char *path, char *buf, int n) reading up to n bytes from the file into buf and returning the number actually read, or -1 if the file can't be opened.
#include <stdio.h>
int read_first_bytes(const char *path, char *buf, int n) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.