So i have used a trie structure for this pset. And i have declared my struct node in the load section as well as root and current which are nodes. I've written my code for check but I need to access root and current in order to be able to do the checking. Obviously, simply using root and current is not working as they haven't yet been declared (check is before load in dictionary.c), but when used in speller.c, root and current will already exist. Any help on how to access them?
Thanks in advance
*****EDIT*****
So I'm pretty sure I tried what you had suggested before posting and for some reason or another it didn't work. I have just tried again, somehow with fewer errors this time. So I moved the following lines of code from the load function to the top of the dictionary.c file underneath the #include statements.
// set up node struct
typedef struct node
{
bool is_word;
struct node* children[27];
}
node;
//initialise root and current
node* root = NULL;
root = malloc(sizeof(node));
node* current = NULL;
Where before (when in load) this was working fine, I now have the following errors...
dictionary.c:27:1: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int] root = malloc(sizeof(node));
^~~~
dictionary.c:27:1: error: redefinition of 'root' with a different type: 'int' vs 'node *' (aka 'struct node ') dictionary.c:26:7: note: previous definition is here node root = NULL;
Any idea what is going on?
Thanks