/* Program: COMPARE.C Author : Kim Moser Date : 2/13/89 System : IBM PC / Borland Turbo-C 2.0 Descrip: Compares file argv[1] with file argv[2]; reports differences. Usage : COMPARE file1 file2 */ #include #include #include #include void main(argc, argv) int argc; char **argv; { FILE *f1, *f2; unsigned long int i; unsigned long int cr1=0, cr2=0; /* How many newlines found so far */ int c1, c2; unsigned long int count = 0; /* How many differences found */ if (argc!=3) { printf( "Usage: COMPARE file1 file2\n" ); exit(1); } if ( (f1=fopen(argv[1],"r"))==NULL ) { printf( "Unable to open '%s' for reading.\n", argv[1] ); exit(1); } if ( (f2=fopen(argv[2],"r"))==NULL ) { fclose(f1); printf( "Unable to open '%s' for reading.\n", argv[2] ); exit(1); } setmode( fileno(f1), O_BINARY ); setmode( fileno(f2), O_BINARY ); printf( "Comparing '%s' with '%s'\n", argv[1], argv[2] ); for( i=0; 1; i++ ) { if ((c1=getc(f1))=='\n') cr1++; if ((c2=getc(f2))=='\n') cr2++; if (c1==EOF && c2==EOF) break; if (c1 != c2) { if (count++==0) printf( "POSITION CHR1 LINE1 CHR2 LINE2\n" ); printf( "%8lu:%5d %5lu %5d %5lu\n", i, c1, cr1, c2, cr2 ); } } if (c1==EOF) printf( "End of file 1 reached" ); else printf( "End of file 1 NOT reached" ); printf( " (fp=%lu).\n", ftell(f1) ); if (c2==EOF) printf( "End of file 2 reached" ); else printf( "End of file 2 NOT reached" ); printf( " (fp=%lu).\n", ftell(f2) ); fclose(f1); fclose(f2); printf( "%lu differences found.\n", count ); }