Advertisement
Guest User

Untitled

a guest
Jan 14th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11. ifstream file1, file2;
  12.  
  13. file1.open("plik.dat", ios::in | ios::binary);
  14. file2.open("plik_porownanie2.dat", ios::in | ios::binary);
  15.  
  16. int fileSize1, fileSize2;
  17. unsigned char buf1;
  18. char * wsk_buf1;
  19. wsk_buf1 = & buf1;
  20. unsigned char buf2;
  21. char * wsk_buf2;
  22. wsk_buf2 = & buf2;
  23. int k=0;
  24. int dodane=0;
  25. int usuniete=0;
  26. int zmienione=0;
  27. int znalazl=0;//ile prawidlowych bajtow//
  28.  
  29. file1.seekg(0, std::ios::end);
  30. fileSize1=file1.tellg();
  31. file1.seekg(0, std::ios::beg);
  32.  
  33.  
  34. file2.seekg(0, std::ios::end);
  35. fileSize2=file2.tellg();
  36. file2.seekg(0, std::ios::beg);
  37.  
  38.  
  39. for (int a=0; a<fileSize1; a++)
  40. {
  41. file1.read((char*) &buf1, 1);
  42.  
  43. for (int b=k; b<fileSize2; b++)
  44. {
  45. file2.read((char*) &buf2, 1);
  46.  
  47. if (buf1==buf2)
  48. {
  49. znalazl++;
  50. k++;
  51. break; //bajty sie zgadzaja//
  52. }
  53.  
  54. else {
  55. if(*(buf1+1)==*(buf2+1))
  56.  
  57. {
  58. cout<<"Bajt znajdujacy sie na"<<i<<" miejscu zamieniono z "<<buf1<< "na "<<buf2<<endl;
  59. zmienione++;
  60. }
  61.  
  62. else if(*buf1==*(buf2+1))
  63. {
  64. cout<<"Bajt"<<buf2<<"dodano"<<endl;
  65. k=k-1;
  66. dodane++;
  67. }
  68.  
  69. else if(*(buf1+1)==buf2)
  70. {
  71. cout<<"Bajt"<<buf1<<"usunieto"<<endl;
  72. usuniete++;
  73. }
  74.  
  75. else { for(int c=i; c<i+50; c++)
  76. {
  77. for (int d=k; d<k+50; d++)
  78. if(buf1==buf2)
  79. int x=c-k;
  80. { cout<<"Bajt "<<buf1<<"znajduje sie na "<<i<<"miejscu, wiec zostalo dodanych"<<x<<"bajtow"<<endl;
  81. k=k+x;
  82. dodane=dodane+x;
  83. }
  84.  
  85. else { cout<<"Bajt "<<buf1<<"zostal usuniety."<<endl;
  86. usuniete++;}
  87.  
  88.  
  89. }
  90. }
  91. }
  92. }
  93. if(fileSize1=znalazl+dodane-usuniete+zmienione)
  94. {
  95. break;
  96. }
  97. else if (fileSize2>fileSize1)
  98. { int p=fileSize2-fileSize1;
  99. cout<<"Od miejsca "<<k<<" zostalo dodanych" <<p<<" bajtow."<<endl;
  100. break;
  101. }
  102.  
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement