I'm sooo close!! My code is running and printing out misspelled words but stopped at message "could not unload dictionary" (I tried on both large and small). However when I run Valgrind, it's reporting a successful memory freed without any leakage.
Here are the screen shots of Valgrind
below is my codes for unload
// recursive function for freeing children memory
void del_trie(node* ptr)
{
for(int i = 0; i < ALPHABETS; i++)
if(ptr->children[i] != NULL)
del_trie(ptr->children[i]);
free(ptr);
return;
}
/** * Unloads dictionary from memory. Returns true if successful else false. */
bool unload(void)
{
node* current = root;
del_trie(current);
if(root != NULL);
return false;
return true;
}
Can someone Plzzz help?? Thanks beforehand.
Edited code:
// recursive function for freeing children memory
void del_trie(node* ptr)
{
for(int i = 0; i < ALPHABETS; i++)
{
if(ptr->children[i] != NULL)
del_trie(ptr->children[i]);
ptr->children[i] = NULL;
}
ptr = NULL;
free(ptr);
return;
}
/** * Unloads dictionary from memory. Returns true if successful else false. */
bool unload(void)
{
node* current = root;
del_trie(current);
root = NULL;
free(root);
if(root != NULL);
return false;
return true;
}