Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(argc, argv)
  5. int argc;
  6. char **argv;
  7. {
  8.   FILE *f1,*f2;
  9.   unsigned char c1,c2;
  10.   long pos = 0;
  11.  
  12.   if (argc != 3)
  13.   {
  14.     fprintf(stderr, "calling convention: %s <file1> <file2>\n", argv[0]);
  15.     return 1;
  16.   }
  17.  
  18.   f1 = fopen(argv[1], "rb");
  19.   if (f1 == NULL)
  20.   {
  21.     perror(argv[1]);
  22.     exit(2);
  23.   }
  24.   f2 = fopen(argv[2], "rb");
  25.   if (f2 == NULL)
  26.    {
  27.     perror(argv[2]);
  28.     exit(2);
  29.    }
  30.  
  31.   while ((!feof(f1)) && (!feof(f2)))
  32.   {
  33.     fread(&c1, 1, 1, f1);
  34.     fread(&c2, 1, 1, f2);
  35.     if (c1 != c2)
  36.     {
  37.       fprintf(stderr,"compare error at position %d\n",pos);
  38.       fclose(f1);
  39.       fclose(f2);
  40.       exit(3);
  41.     }
  42.     pos++;
  43.   }
  44.  
  45.   if (feof(f1) != feof(f2))
  46.   {
  47.     fprintf(stderr,"files have different sizes\n");
  48.     fclose(f1);
  49.     fclose(f2);
  50.     exit(4);
  51.   }
  52.  
  53.   fclose(f1);
  54.   fclose(f2);
  55.  return 0;
  56. }
  57.