why this program release un exception

please anyone kindly compile this program and tell me why that short program throw an exception when it run at the function CollectInformation(Table&table,char* fileName) in main.cpp
for your information I am using visual stadio 6 and windows vista
its 3 files
and an directory
TXT&HTML Files\*.txt

main.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <windows.h>
#include <fstream>
#include <cstdlib>
#include"Table.h"
using namespace std;
int SeparateWords(string Line,bool newline,int& i)
{
	static int index;
	if(newline)
	{
		index=0;
		i=0;
		//return 0;
	}
	while(Line[index]==' '&&index<Line.length()-1)
	{
		index++;
	}
	i=index;
	while(Line[index]!=' '&&index<Line.length()-1)
	{
		index++;
	}
	if(index==Line.length()-1)
		index++;
	return index;
}
void CollectInformation(Table&table,char* fileName)
{

	char* path1;
	path1="TXT&HTML Files\\";
    string path2("");
	path2.append(path1);
	path2.append(fileName);
	int size=path2.size()+1;
	char* path=new char[size];
	path=new char[size];
	for(int i=0;i<size;i++)
	{
		path[i]=path2[i];
		if(path[i]=='\\')
		{
			//path[i]='\\';
				
		}

	}
	ifstream file(path);
	
	string stream;//[500];
	int line=0;
	Table check(table.Size());
	while(!file.eof())
	{
		
		char buffer[2000];
		line++;
		file.getline(buffer,2000);
		int i=0;
		stream="";
		stream.append(buffer);
		if(stream.length()!=0)
		{
			int k=SeparateWords(stream,true,i);
			while(i<stream.length()-1)
			{
				if(i!=k)
				{
					string word("");
					word.resize(k-i);
					int j=0;
					if(k-i==1)
					{
						word[0]=stream[i];
					}
					else
					{
						for(;i<k+1;i++,j++)
						{
							word[j]=stream[i];
						}
					}
					if(table.Contain(word))
					{
						string newData("");
						if(!check.Contain(word))
						{
							check.Add(word," ");
							newData.append(fileName);
							newData.append(":\n");
						}
						newData.append("Line");
						char* c=new char[10];
						newData.append(itoa(line,c,10));
						newData.append(" :");
						newData.append(stream);
						newData.append("\n");
						table.Append(word,newData);
					}
				}
				k=SeparateWords(stream,false,i);
			}
		}
		
	}
}
void main()
{
	ifstream keyWords;
	string keyWord;
	int tableSize=100;
	Table table(tableSize);
	while(1)
	{
		bool done=true;
		keyWords.open("KeyWords.txt");
		table.Resize(tableSize);
		while(!keyWords.eof())
		{
			keyWords>>keyWord;
			if(table.Contain(keyWord))
			{
				done=false;
				break;
			}
			else
			{
				table.Add(keyWord," ");
			}
		}
		if(!done)
		{
			keyWords.close();
			tableSize=tableSize*2;
			table.Resize(tableSize);
			done=true;
		}
		else
		{
			break;
		}
	}
	WIN32_FIND_DATA FindData;
	HANDLE hFind;
	hFind = FindFirstFile("TXT&HTML Files\\*.txt", &FindData);
	CollectInformation(table,FindData.cFileName);
	while (FindNextFile(hFind, &FindData))
	{
			CollectInformation(table,FindData.cFileName);
	}
	WIN32_FIND_DATA FindData2;
	HANDLE hFind2;
	hFind2 = FindFirstFile("TXT&HTML Files\\*.html", &FindData2);
		CollectInformation(table,FindData.cFileName);
	while (FindNextFile(hFind2, &FindData2))
	{
			CollectInformation(table,FindData.cFileName);
	}
	while(true)
	{
		char word[50];
		cin>>word;
		if(table.Contain(word))
		{
			string key;
			key.append(word);
			cout<<"word ""<<word<<"" exists in:\n";
			for(int i=0;i<table.Get(key).length();i++)
			{
				cout<<table.Get(key)[i];
			}
			cout<<"\n";
			
			
		}
		else
		{
			cout<<"word is not found in the keywords\n";
		}
	}	
} 

                      


Table.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
#include"Table.h"

Table::Table()
{
}
Table::Table(int _size)
{
	elements=new string[_size];
	size=_size;
}
bool Table::Contain(string key)
{
	if(elements[H(key)]!="")
		return true;
	return false;
}
void Table::Add(string key,string value)
{
	elements[H(key)]=value;
}
int Table::Size()
{
	return size;
}
void Table::Resize(int newSize)
{
	delete[] elements;
	elements=new string[newSize];
	size=newSize;
}
void Table::Update(string key,string value)
{
	elements[H(key)]=value;
}
void Table::Append(string key,string newData)
{
	elements[H(key)].append(newData);
}
string& Table::Get(string key)
{
	return elements[H(key)];
}
int Table::H(string key)
{
	int h(0);
	for(int i=0;i<key.size();i++)
	{
		h=31*h+int(key.at(i));
	}
	return h%size;
}
Table::~Table()
{
	delete elements;
}


Table.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream.h>
#include<string>
using namespace std;
class Table
{
private:
	string *elements;
	int size;
	int H(string key);
public:
	Table(int _size);
	Table();
	int Size();
	bool Contain(string element);
	void Add(string key,string value);
	void Update(string key,string value);
	void Append(string key,string newData);
	void Resize(int newSize);
	string& Get(string key);
	~Table();
};


If someone is interested to help me I can send him the whole program if he post his email
thanks
Last edited on
Topic archived. No new replies allowed.