-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
106 lines (96 loc) · 1.84 KB
/
Copy pathmain.cpp
File metadata and controls
106 lines (96 loc) · 1.84 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <fstream>
#include <string>
extern "C" int find(int* intValueOfWord, int* intValueOfWord2);
using namespace std;
int main(int argc, char* argv[])
{
fstream file;
char word[150];
char word2[50];
char tempS[50];
char temp;
int intValueOfWord[150];
int intValueOfWord2[50];
int found = 0;
char wc[50];
file.open(argv[1]);
word[0] = 0;
int i = 0;
int j = 0;
while (!file.eof())
{
i = -1;
do { //for gaps
i++;
file.get(wc[i]);
} while (wc[i] == ' ' || wc[i] == '\t' || wc[i] == '\n');
temp = wc[i];
wc[i] = 0;
file >> tempS;
if (file.eof() == 1)
{ //get the word 2 as the last word
word2[0] = temp; //strcpy temp to word2
for (i = 0; tempS[i] != 0 && i < 49; ++i) // strconcanate tempS to word2
{
word2[i + 1] = tempS[i];
}
word2[i + 1] = 0;
}
else
{
if (word[0] == 0) //strcpy tempS to word
{
for (i = 0, j = 0; wc[i] != 0 && j < 49; ++i, ++j) //strconcanate wc to word
{
word[j] = wc[i];
}
word[j] = temp;
j++;
for (i = 0, j; tempS[i] != 0 && j < 49; ++j, ++i)
{
word[j] = tempS[i];
}
word[j] = 0;
}
else
{
for (i = 0; wc[i] != 0 && j < 49; ++i, ++j) //strconcanate wc to word
{
word[j] = wc[i];
}
word[j] = temp; // strconcanate temp to word
j++;
i = 0;
for (; tempS[i] != 0 && j < 49; ++j) //strconcanate next word to word
{
word[j] = tempS[i];
++i;
}
word[j] = 0;
}
}
}
file.close();
cout << word << endl;
cout << word2 << endl;
int k = 0;
while (word[k] != '\0')
{
intValueOfWord[k] = (int)word[k];
k++;
}
intValueOfWord[k] = 0;
k = 0;
while (word2[k] != '\0')
{
intValueOfWord2[k] = (int)word2[k];
k++;
}
intValueOfWord2[k] = 0;
k = 0;
found = find(intValueOfWord, intValueOfWord2);
cout << found << endl;
getchar();
getchar();
}