-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiscFunctions.cpp
68 lines (54 loc) · 1.36 KB
/
miscFunctions.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
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <fstream>
using namespace std;
int split1(string input_string, char delimiter, string arr[], int arr_size)
{
int index = 0;
int length = input_string.length();
if(input_string == "")
{
return 0;
}
for(int i = 0; i < length; i++)
{
if(input_string[i] == delimiter)
{
index++;
if(index +1 > arr_size)
{
return -1;
}
}
else
{
arr[index] = arr[index] + input_string[i];
}
}
return index + 1;
}
int readRiddles(string file_name, string riddles[][2], int arr_size) {
ifstream file;
string lines = "";
int num_riddles = 0;
file.open(file_name);
if(file.is_open())
{
while (!file.eof())
{
getline(file, lines);
if(lines.length() > 0)
{
string temp[arr_size];
for (int n = 0; n < arr_size; n++)
{
temp[n] = ""; //reset the temporary array
}
int split_value = split1(lines, '~', temp, arr_size);
riddles[num_riddles][0] = temp[0];
riddles[num_riddles][1] = temp[1];
num_riddles++;
}
}
}
return num_riddles;
}