0

i ve been working struggling so much... please, a hint why i can make it work. I don t know how to return the result and make sure that the conditions are followed. here are my codes for unload :
` /* Frees all the children nodes one by one recursion, except the root */ void freeNode(node *temp_pointer) { //go through node's children // make sure to free the childrens and come back to the parent for (int letter_position = 0; letter_position < 27; letter_position++) { //if children is a pointer so a parent to his children, check also that children) if (temp_pointer->children[letter_position] != NULL) { freeNode(temp_pointer->children[letter_position]); }

    // when all children are null, it time to free node
    else
    {
        free(temp_pointer);
    }
}

}

/** * Unloads dictionary from memory. Returns true if successful else false. */ bool unload(void) { //FILE *fp = NULL;

//go through node's children  // make sure to free the childrens and come back to the parent
for (int letter_position = 0; letter_position < 27; letter_position++)
{
    //if children is a pointer so a parent to his children, check also that children)
    if (root->children[letter_position] != NULL)
    {
        freeNode(root->children[letter_position]);
        return false;
    }
    else
    {
        free(root);
        return true;
    }
}

} `

  • i had to remove the the free(temp_pointer) from the loop. – Genevie Sep 8 '17 at 17:55
0

You have to free root if you iterated over all children and freed all which are not NULL. So you have to put the free(root) after the loop.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .