我需要逐行比较两个文件。其中一个文件在行尾有一个类似 ^M 的字符。我想在比较时排除它。我还需要找到匹配的行数。这是我的代码。如何添加该 ^M 以及在哪里增加行 contor?
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;
}
void main(int argc, char *argv[] )
{
FILE *fpread, *fpread2;
char filebuff[MAXLINE];
char filebuff2[MAXLINE];
int var = 0;
int linecount = 0;
printf ("COMPARE RESULT %d \n",compareFile("file1","file2"));