Unexpected break in main() using larger file on working code

I have been given multiple .txt files of varying sizes (from just 50 to 3 million). Each line contains two 'names' of 8 randomly generated characters separated by a comma, e.g. "Xtimshgy,Rjbjutyq".
Each line is to be considered as the 'name' of one man followed by the 'name' of his westerly neighbour, with all the men standing in a specific order from east to west. If you view the file as having two columns, therefore, each column will contain the same data, in a different order, with the first column also containing the 'name' of the man on the eastern end of line and the second, the 'name' of the most western man.
The lines in the .txt files have been shuffled from the original order and my task is to reorder the men using only the information I've been given and be able to do so to the 3 mil men file.

I have successfully produced the code in VS that does the task in hand when I input a file that contains 10,000 lines (and also smaller variations) but as soon as I try to use the 100,000 line file (the next smallest option available), the debugger breaks as the code enters the main() function - before the debugger reaches the line of code that tells it to even look at the file, which is the only thing I've changed. It throws an unhandled exception and points me to line 626 of crtexe.c which is:
 
  mainret = main(argc, argv, envp);


What I want to know is, why does it break, and is there anything I can do to prevent it from doing so?

Here is my code when using 100,000 lines
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
map<string, string> west;	// W to E
map<string, string> east;	// E to W
list<string> result;

void insertEast(string et, string wt)
{
	east[et] = wt;
}

void insertWest(string et, string wt)
{
	west[wt] = et;
}
int main()
{
	ifstream myFile;
	myFile.open("100K.txt");	//change only text file name and
	const int arraySize = 100000;	//arraySize to use different size file

	string myArray[(arraySize - 1)];
	string line;	// Full original pair
	string et;	// Eastern name per pair
	string wt;	// Western neighbour in pair
	int i = 0;
	int j = 0;
	
	while (myFile.good())
	{
		myFile >> myArray[j];
		j++;
	}
	while (i < (arraySize - 1))  // Until result complete
	{
		if (myArray[i] == "")
		{
			i++;
		}
		else
		{
			line = myArray[i];
			et = line;
			wt = line;
			et.erase(8, 16);
			wt.erase(0, 9);
			
			insertEast(et, wt);
			insertWest(et, wt);
			myArray[i] = "";

			i++;
		}
	}

	//domain and range are set<string>'s
	set<string> dmw = domain(west);	//west[*]=
	set<string> rnw = range(west);	//west[]= *
	set<string> dme = domain(east);	//east[*]=
	set<string> rne = range(east);	//east[]= *
	pair<string,string> current;

	//setDiff is also a set<string>
	string mostEasterly = *(setDiff(dme, rne).begin());
	string mostWesterly = *(setDiff(dmw, rnw).begin());

	cout << "Eastern end: " << mostEasterly << endl;
	cout << "Western end: " << mostWesterly << endl << endl;

	current = *east.begin();
	do
	{
		result.push_back(current.first);
		current.first = east[current.first];
	} while (current.first != mostWesterly);
	result.push_back(current.first);

	current.second = result.front();
	while (current.second != mostEasterly)
	{
		result.push_front(current.second);
		current.second = west[current.second];
	}

	cout << "Size: " << result.size() << endl << endl;

	return 0;
}
Hi,

Your array myArray is on the stack, and you are probably overflowing it. Try a std::vector instead, it puts it's data on the heap.
That worked a treat! Thanks TheIdeasMan! It never occurred to me it would be that simple!
Topic archived. No new replies allowed.