-
Notifications
You must be signed in to change notification settings - Fork 1
/
partB.cpp
60 lines (48 loc) · 1.08 KB
/
partB.cpp
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
#include <iostream>
#include <fstream>
#include <string>
#include "BinarySearchTree.h"
#include "Node.h"
string SINGLE_WORDS_FILE_PATH = "single_words_test.txt";
string SENTENCES_FILE_PATH = "sentences_test.txt";
// Read from file and insert the words in the BST
void read_file(string input_file);
void read_file(string input_file)
{
ifstream input_file_object;
input_file_object.open(input_file);
if (!input_file_object.is_open()) return;
char ch = ' ';
string word_from_file = "";
while (input_file_object >> word_from_file)
{
ch = word_from_file.back();
if (ch <'A' && ch > 'Z' && ch <'a' && ch > 'z')
word_from_file.pop_back();
cout << word_from_file;
}
}
int main(int argc, char **argv)
{
string input_path = "";
bool is_set_input_path = false;
for (int i = 0; i < argc; i++)
{
if (argv[i] == SINGLE_WORDS_FILE_PATH || argv[i] == SENTENCES_FILE_PATH)
{
input_path = argv[i];
is_set_input_path = true;
break;
}
}
if (is_set_input_path)
{
read_file(input_path);
}
else if (!is_set_input_path)
{
cout << "Error";
return 0;
}
return 0;
}