Compare two files
<p>So, I'm trying to write function, which compares content of two files, but I doesn't work.</p>

<p>I want it to return 1 if files are the same, and 0 if different.</p>

<p>ch1 and ch2 works as a buffer, and I used fgets to get content of my files.</p>

<p>I think there is something wrong with the eof pointer, but I'm not sure. FILE variables are given within command line.</p>

<p>P.S. It works with small files with size under 64KB, but gets anyoned with larger files (700MB movies for example, or 5MB mp3).</p>

<p>Any ideas, how to work it out?</p>

<pre><code>int compareFile(FILE* file_compared, FILE* file_checked)
{
    bool diff = 0;
    int N = 65536;
    char* b1 = (char*) calloc (1, N+1);
    char* b2 = (char*) calloc (1, N+1);
    size_t s1, s2;

    do {
        s1 = fread(b1, 1, N, file_compared);
        s2 = fread(b2, 1, N, file_checked);

        if (s1 != s2 || memcmp(b1, b2, s1)) {
            diff = 1;
            break;
        }
      } while (!feof(file_compared) || !feof(file_checked));

    free(b1);
    free(b2);

    if (diff) return 0;
    else return 1;
}
</code></pre>

<p>EDIT: I've improved this function with inclusion of Your anwers. But it's only comparing first buffer only -> but with exception -> I figured out that it stops reading file until it reaches 1A character (attached file). How can We make it work?</p>

<p>EDIT2: Task solved (working code attached). Thanks to everyone for help!</p>
