The only code I have added to the top of my dictionary.c
is this
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "dictionary.h"
/**
* Returns true if word is in dictionary else false.
*/
// Structure of trie
typedef struct node
{
bool is_word;
struct node* children[27];
}
node;
// Vaiables used for the trie
node* root = malloc(sizeof(node));
node* triepointer = root;
However, the compiler tells me that malloc
doesn't work as initializer element is not a compile-time constant
.
What does the error mean? (googled and it seems that I need to use a constant here, but which part of this line is missing a constant and why?) Also, I see that Zamyla's guide doesn't use malloc
when creating the root node. How can root
be used if memory isn't allocated for it?