Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- ifstream file1, file2;
- file1.open("plik.dat", ios::in | ios::binary);
- file2.open("plik_porownanie2.dat", ios::in | ios::binary);
- int fileSize1, fileSize2;
- unsigned char buf1;
- char * wsk_buf1;
- wsk_buf1 = & buf1;
- unsigned char buf2;
- char * wsk_buf2;
- wsk_buf2 = & buf2;
- int k=0;
- int dodane=0;
- int usuniete=0;
- int zmienione=0;
- int znalazl=0;//ile prawidlowych bajtow//
- file1.seekg(0, std::ios::end);
- fileSize1=file1.tellg();
- file1.seekg(0, std::ios::beg);
- file2.seekg(0, std::ios::end);
- fileSize2=file2.tellg();
- file2.seekg(0, std::ios::beg);
- for (int a=0; a<fileSize1; a++)
- {
- file1.read((char*) &buf1, 1);
- for (int b=k; b<fileSize2; b++)
- {
- file2.read((char*) &buf2, 1);
- if (buf1==buf2)
- {
- znalazl++;
- k++;
- break; //bajty sie zgadzaja//
- }
- else {
- if(*(buf1+1)==*(buf2+1))
- {
- cout<<"Bajt znajdujacy sie na"<<i<<" miejscu zamieniono z "<<buf1<< "na "<<buf2<<endl;
- zmienione++;
- }
- else if(*buf1==*(buf2+1))
- {
- cout<<"Bajt"<<buf2<<"dodano"<<endl;
- k=k-1;
- dodane++;
- }
- else if(*(buf1+1)==buf2)
- {
- cout<<"Bajt"<<buf1<<"usunieto"<<endl;
- usuniete++;
- }
- else { for(int c=i; c<i+50; c++)
- {
- for (int d=k; d<k+50; d++)
- if(buf1==buf2)
- int x=c-k;
- { cout<<"Bajt "<<buf1<<"znajduje sie na "<<i<<"miejscu, wiec zostalo dodanych"<<x<<"bajtow"<<endl;
- k=k+x;
- dodane=dodane+x;
- }
- else { cout<<"Bajt "<<buf1<<"zostal usuniety."<<endl;
- usuniete++;}
- }
- }
- }
- }
- if(fileSize1=znalazl+dodane-usuniete+zmienione)
- {
- break;
- }
- else if (fileSize2>fileSize1)
- { int p=fileSize2-fileSize1;
- cout<<"Od miejsca "<<k<<" zostalo dodanych" <<p<<" bajtow."<<endl;
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement