If your files do not match, can they be the same size? If not, you can immediately determine the file sizes (fseek to the end, ftell to determine the position), and if they are different, you know that they do not match without comparing the data. If the size is the same, do not forget to return to the beginning.
If you read your files in large memory buffers and compare each buffer with memcmp (), you improve performance. You donβt have to read the whole file right away, just set a large buffer size and read blocks of this size from each file, for each iteration of the comparison through your loop. Memcpy function will work with 32-bit values, but not with 8-bit bytes.
source share