#include <stdio.h>

int main(argc, argv) 
   int argc;
   char *argv[];
{
   FILE *f1, *f2;
   register int i, j;
   unsigned long offset = 0;

   --argc; 
   if (argc != 2) {
       fprintf(stderr, "usage: cmp file1 file2\n");
       return 1;
   }

   f1 = fopen(*++argv, "rb");
   if (f1 == NULL) {
      fprintf(stderr, "cmp: can't open \"%s\" for read\n", *argv);
      return 1;
   }
   f2 = fopen(*++argv, "rb");
   if (f2 == NULL) {
      fprintf(stderr, "cmp: can't open \"%s\" for read\n", *argv);
      return 1;
   }
   while ((i = getc(f1)) != EOF) {
      if ((j = getc(f2)) != i) {
	 fprintf(stderr, "miscompare at offset %ld; %.2x vs %.2x\n",
	     offset, i,  j);
	 return 1;
      }
      offset++;
   }
   fclose(f1);
   fclose(f2);

   return 0;
}
