Part 1 completed
This commit is contained in:
parent
b3fcaf0075
commit
ebb6e83745
|
@ -0,0 +1,43 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
auto startmain = chrono::high_resolution_clock::now();
|
||||
if(argc != 5)
|
||||
{
|
||||
cout <<"usage: ./partitioner.out <path-to-file> <pattern> <search-start-position> <search-end-position>\nprovided arguments:\n";
|
||||
for(int i = 0; i < argc; i++)
|
||||
cout << argv[i] << "\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *file_to_search_in = argv[1];
|
||||
char *pattern_to_search_for = argv[2];
|
||||
int len = sizeof(pattern_to_search_for);
|
||||
int search_start_position = atoi(argv[3]);
|
||||
int search_end_position = atoi(argv[4]);
|
||||
int find = 0;
|
||||
ifstream file(file_to_search_in, ios::binary);
|
||||
//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;
|
||||
}
|
||||
}
|
||||
if(find == 0) cout << "[1] didn't find\n";
|
||||
auto endmain = std::chrono::high_resolution_clock::now();
|
||||
chrono::duration<double> mainduration = endmain - startmain;
|
||||
cout << mainduration.count() << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue