-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindoffset.cpp
More file actions
63 lines (54 loc) · 1.52 KB
/
findoffset.cpp
File metadata and controls
63 lines (54 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <regex>
using std::cout, std::endl;
int main(int argc, char** argv) {
if (argc < 3) {
cout << "Input: <file path> <offset>";
exit(EXIT_FAILURE);
}
std::string document_path = std::string(argv[1]);
int targetOffset = std::atoi(argv[2]);
std::string target;
std::ifstream document(document_path);
if (!document) {
std::cerr << "Error opening file " << document_path << endl;
exit(EXIT_FAILURE);
}
std::string line;
std::getline(document, line); //get url and doc
// Check <title> tag
std::getline(document, line);
cout << "======= TITLE ======" << endl;
uint32_t offset = 0;
// Get title words
std::getline(document, line);
std::istringstream titleIss(line);
std::string word;
uint32_t numTitleWords = 0;
while (titleIss >> word) {
cout << offset << ": " << word << endl;
if (offset == targetOffset) {
target = word;
}
++offset;
}
// Check </title> tag
std::getline(document, line);
// Check <words> tag
std::getline(document, line);
cout << "======= WORDS ======" << endl;
std::getline(document, line);
std::istringstream bodyIss(line);
while (bodyIss >> word) {
cout << offset << ": " << word << endl;
if (offset == targetOffset) {
target = word;
}
++offset;
}
cout << "TARGET: " << target << endl;
}