cybersecurity · intermediate · ~15 min · safe pentest lab
Stream-compare files via fread chunks.
Decide whether two files hold identical bytes, streaming them in chunks rather than slurping each into memory.
Implement int files_match(const char *a, const char *b) that compares the two files byte for byte.
a, b: NUL-terminated paths. The grader creates the test files locally before each check.Returns an int:
1 if both files open and have exactly the same bytes.0 if both open but differ (in content or length).-1 if either file cannot be opened.both contain "hello world" -> 1
"hello world" vs "hello WORLD" -> 0
one path missing -> -1
Two NUL-terminated paths a and b to local files the grader created.
An int: 1 if identical, 0 if both open but differ, -1 if either can't be opened.
Stream the comparison in fixed-size chunks; no whole-file loads.
#include <stdio.h>
int files_match(const char *a, const char *b) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.