Freezing at Constructor

Hello, I am working on a school assignment to make a 20 Questions-style guessing game. The program stores the information in a tree with question nodes and name nodes-- nothing too complicated there. The game itself is a separate class that contains a GuessingGameTree and provides the necessary functions for client code to play the game without knowledge of either the tree or the nodes.

I'm afraid I've run into a bit a snag while debugging, though. When the constructor for the tree finishes, the program just freezes. I've used test output to find the problem. The debugger just hits the end brace, then stays there even when I try to keep moving.

Here is the relevant code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
GuessingGame :: GuessingGame(const char* fileName)
	{
		cout << "Creating game...\n";
		
		ifstream inStream;
		inStream.open(fileName);
		
		if(inStream.fail())
		{
			cout << "Input file opening failed.";
			exit(1);
		}	
		
		gameTree = new GuessingGameTree(inStream);
		
		cout<< "Closing input stream...\n";
		inStream.close();
		
		current = gameTree->getRoot();
		previous = NULL;
	}


1
2
3
4
5
6
7
8
9
// GuessingGameTree functions

	GuessingGameTree :: GuessingGameTree(ifstream& tf)
	{	
		cout << "Creating tree...\n";
		root = readTree(tf);
		cout << "Root is set...\n";
		return;
	}                                                  //Program hangs here. 



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
GuessingGameNode* GuessingGameTree :: readTree(ifstream& tf)
	{
		cout << "Reading tree...\n";
		// The type of node: 'N' for a NameNode, 'Q' for a QuestionNode
		char typeArray[1];
		tf.getline(typeArray, 10);
		char type = typeArray[0];
		
		
		// Stores the data in an array of characters until it
		// can be converted into a string later for the constructors
		char data[100];
		
		
		// Checks the type of the node and then creates a new 
		// GuessingGameNode based on the type
		if(type == 'N')
		{
			tf.getline(data, 100);
			
			string dataStr(data);
	
			cout << "Creating name node...\n";
			NameNode* n = new NameNode(dataStr);
			
			return n;
		}
		else
		{
			assert (type == 'Q');
			tf.getline(data, 100);
			string dataStr(data);
			
			// Recursively calls readTree for the yes and no branches
			cout << "Creating question node...\n";
			QuestionNode* q = new QuestionNode(readTree(tf), 
				readTree(tf), dataStr);

			return q;
		}



When I run the code, it prints everything up to "Root is set..." but not "Closing input stream..."

Any assistance you could grant me would be greatly appreciated. Thanks!
Well, I've been trying to solve the problem and I'm now fairly certain that it's a segfault that is occuring. I'm pretty sure the only place it could be caused by is ReadTree.
Topic archived. No new replies allowed.