Binary Trees problem loading txt
Nov 16, 2013 at 9:27pm UTC
Code deleted due to personal reasons. I fixed my problem by re-writting the code.
Thank you for your help
Last edited on Nov 18, 2013 at 12:11am UTC
Nov 17, 2013 at 1:12am UTC
!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.
Nov 17, 2013 at 1:38am UTC
Code deleted due to personal reasons. I fixed my problem by re-writting the code.
Thank you for your help
Last edited on Nov 18, 2013 at 12:10am UTC
Nov 17, 2013 at 3:47pm UTC
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.