cybersecurity · intermediate · ~15 min · safe pentest lab

Compare two files by content hash

Stream-compare files via fread chunks.

Challenge

Implement int files_match(const char *a, const char *b) returning 1 if both files exist and have identical bytes, 0 if both exist but differ, -1 if either can't be opened.

Use a streaming compare rather than reading whole files into memory.

Starter code

#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.