This is a re-do that does about what you want. It uses two very small text files, and correctly determines that one letter is different.
I wouldn't try de-bugging from the command line, if possible.
Code:
#include <stdio.h>
int main(void)
{
FILE *file1, *file2;
char c1, c2, str1[19], str2[19];
unsigned long int errors = 0;
unsigned long int count = 0;
int file1ok, file2ok;
printf("\n\n");
/* while(--argc > 0)
printf("%s\n", argv[argc]);
*/
file1 = fopen("compare1.txt", "rb");
file2 = fopen("compare2.txt", "rb");
if(file1 == NULL)
{
printf("Error: can't open file number one.\n");
}
if(file2 == NULL)
{
printf("Error: can't open file number two.\n");
}
else
{
while(1)
{
file1ok = fread(&c1, sizeof(char), 1, file1);
file2ok = fread(&c2, sizeof(char), 1, file2);
if(file1ok && file2ok)
{
if((c1 ^ c2) != 0)
errors++;
count++;
printf(" %c", c1);
}
else
break;
} /* end of while */
fclose(file1);
fclose(file2);
printf("\nResult: %lu bits compared. %lu equal bits found\n\n", count, count-errors);
} /* end of else */
system("pause");
return 0;
}
The file contained just this:
Now is the time for - compare1.txt
Now *s the time for - compare2.txt
The file handling logic is still in need of some work, as dwk mentions below. Indentation problem is fixed - it was done on a different compiler from what I usually use, on a different computer. Since FC (file compare), is part of every windows and dos OS, and does a better job, I didn't worry about the portability of this learning tool.