update part 1
This commit is contained in:
parent
ebb6e83745
commit
dd0de524ac
|
@ -24,18 +24,29 @@ int main(int argc, char **argv)
|
|||
int search_start_position = atoi(argv[3]);
|
||||
int search_end_position = atoi(argv[4]);
|
||||
int find = 0;
|
||||
int pid = getpid();
|
||||
ifstream file(file_to_search_in, ios::binary);
|
||||
int len2 = search_end_position - search_start_position;
|
||||
string buffer;
|
||||
buffer.resize(len2);
|
||||
// file.seekg(i);
|
||||
file.read(&buffer[0], len2);
|
||||
//TODO
|
||||
for(int i = search_start_position; i < search_end_position; ++i) {
|
||||
char *buffer = new char[len];
|
||||
file.seekg(i);
|
||||
file.read(buffer, len);
|
||||
if(!strcmp(buffer, pattern_to_search_for)) {
|
||||
cout << "[1] found at" << " " << i << endl;
|
||||
find = 1;
|
||||
}
|
||||
auto a = buffer.find(pattern_to_search_for);
|
||||
if(a != string::npos) {
|
||||
cout << "[" << pid << "]" << " found at" << " " << a<< endl;
|
||||
}
|
||||
if(find == 0) cout << "[1] didn't find\n";
|
||||
else {
|
||||
cout << "[" << pid << "]" << " didn't find\n";
|
||||
}
|
||||
// for(int i = search_start_position; i < search_end_position; ++i) {
|
||||
// if(!strcmp(buffer, pattern_to_search_for)) {
|
||||
// cout << "[" << pid << "]" << " found at" << " " << i << endl;
|
||||
// find = 1;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if(find == 0) cout << "[" << pid << "]" << " didn't find\n";
|
||||
auto endmain = std::chrono::high_resolution_clock::now();
|
||||
chrono::duration<double> mainduration = endmain - startmain;
|
||||
cout << mainduration.count() << endl;
|
||||
|
|
Loading…
Reference in New Issue