Binary Trees problem loading txt

Code deleted due to personal reasons. I fixed my problem by re-writting the code.
Thank you for your help
Last edited on
!indent

char buf[MAX_CHARS_PER_LINE]; is local to `loadFile()', ¿are you copying the content when you create the nodes?

Provide a minimal snip that does reproduce your problem.
Code deleted due to personal reasons. I fixed my problem by re-writting the code.
Thank you for your help
Last edited on
1
2
3
4
5
6
7
8
	TreeNode(void *transfer)
	{
		// Constructor.  Make a node containing str.
		char* data=static_cast<char*>(transfer);
		item = data;
		left = NULL;
		right = NULL;
	}
you are not copying the content. When `loadFile()' ends your `item' pointers would become invalid.
1
2
		item = new char[strlen(data)+1];
		strcpy(item, data);
or better, make `item' an std::string.

I don't understand the purpose of your castings. If you want to receive a const char* then ask for a const char*
Topic archived. No new replies allowed.