I am trying to compare two files through command line arguments. The result is that the program returns the line number at which the files differ based on the first byte that it encounters that differs. It should be working just fine, but it always returns a line value of 1. I cant figure out why...
Code:#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *fp, *fr; int line = 1; char c, d; fp=fopen(argv[1], "r"); fr=fopen(argv[2], "r"); while(((c=fgetc(fp)) != EOF) || ((d=fgetc(fr)) != EOF)){ if(c != d){ printf("File differs at line %d", line); exit(0); } if(c == '\n'){ line++; } } system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks




