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.
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.