0

This is my struct node defined in dictionary.h

typedef struct node
{
    bool is_word;
    struct node* children[27];
}
node;

struct node* root;

This is the part of the code I'm having problems with

bool unload(void)
{
    return trieunload(root);
}

bool trieunload(node* p)
{
    for (int i = 0; i < 27; i++)
    {
        if(p -> children[i] != NULL)
        {
            trieunload(p -> children[i]);
        }
    }
    free *p;
    return true;
}

What I'm trying to do is pass the address of the root node use it in the function trieunload to free my trie. However, no matter what combinations of p and *p I try to use, I can't seem to get the code to compile. Any suggestions on what I have done wrong with my syntax?

1

It would have helped if you had told us exactly what the compile errors were. However, with a cursory look at the code, I see this:

free *p;

Your usage of free() is incorrect. For starters, it needs parentheses. Next, it doesn't need the *. To free the memory pointed to by p, the correct form in this case would be

free(p);

If there are other issues, you will need to post the error messages so that they can be interpreted. Generally, these error messages are quite literal.

If this answers your question, plese click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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