Write a program to compare two text files. The names of the files are to be supplied as command line arguments. The program should write a message to the screen indicating that the files are exactly the same or that there are differences. If the files differ, the program should write to the screen the line numbers for the lines that are not the same.
i have this one almost right, but my program will only find the first difference and i have to find all the differences... how do you suggest i go about this?
#include <stdio.h>
int main(int argc, char *argv[]){
char ch1, ch2, same;
int l;
FILE *fp1, *fp2;
fp1 = fopen( argv[1], "r" );
fp2 = fopen( argv[2], "r" );
l = 1;
same = 1;
while( ch1 != EOF ){
ch1 = fgetc( fp1 );
ch2 = fgetc( fp2 );
if( ch1 != ch2 ){
printf( "\nFiles differ at line number %d\n", l );
same = 0;
break;
}
if( ch1 == '\n' ) l++;
}
if( same ) printf("\nFiles are the same.\n");
fclose( fp1 );
fclose( fp2 );
return(0);
}