Advertisement
cd62131

Compare Files

Feb 6th, 2014
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc, char **argv) {
  4.   if (argc < 2) {
  5.     fprintf(stderr, "Usage: %s FILE1 FILE2\n", argv[0]);
  6.     exit(EXIT_FAILURE);
  7.   }
  8.   FILE *f1 = fopen(argv[1], "r");
  9.   FILE *f2 = fopen(argv[2], "r");
  10.   int c1, c2;
  11.   while (1) {
  12.     c1 = fgetc(f1);
  13.     c2 = fgetc(f2);
  14.     if (c1 != c2) {
  15.       puts("differ");
  16.       exit(EXIT_SUCCESS);
  17.     }
  18.     if (c1 == EOF) break;
  19.   }
  20.   puts("same");
  21.   return EXIT_SUCCESS;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement