Noam_15

לבדוק האם שני קבצים הם זהים

Mar 16th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. enum status {success, fail};  
  4. void main() {
  5.     enum status sss=success;
  6.     FILE *fp1,*fp2;
  7.     int q1,q2;
  8.     char str[200];
  9.     printf("Enter first path:  ");
  10.     gets(str);
  11.     fp1 = fopen(str , "rb");
  12.  
  13.     printf("Enter second path:  ");
  14.     gets(str);
  15.     fp2 = fopen(str , "rb");
  16.  
  17.     if(fp1 == NULL || fp1 == NULL) {
  18.         printf("Can't open file\n");
  19.         exit(0);
  20.     }
  21.  
  22.     do{
  23.         if (feof(fp1)){
  24.             if (!feof(fp2)) sss=fail;
  25.             break;
  26.         }
  27.  
  28.         if (sss==fail) break;
  29.         fread(&q1, sizeof(int) ,1,fp1);
  30.         fread(&q2, sizeof(int) ,1,fp2);
  31.         if (q1 != q2){
  32.             printf("Different value\n");
  33.             sss=fail;
  34.         }
  35.     }while(1);
  36.  
  37.     (sss==success)? printf("The files are the same!\n"): printf("The files are NOT the same!\n");
  38.     fclose(fp1);
  39.     fclose(fp2);
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment