typedef struct node bool is_word; struct node *children;node;node *root = malloc(27 * sizeof(struct node));When I shot to compile, I get the following error:

dictionary.c:20:14: error: initializer aspect is not a compile-time constantnode *root = malloc(27 * sizeof(struct node));What am i doing wrong?

Thanks in advancement for your help.

You are watching: Initializer element is not a compile time constant


It looks prefer you are trying to develop and allocate storage for root external of key or any type of other role call. This is no allowed. Over there are details actions you deserve to do external of main. This all need to be points that have the right to be coded at compile time. For instance, you deserve to declare a an international var exterior of main. However, girlfriend can"t do things exterior of key or a role that need to be done at run time, like assigning values to variables or allocating memory through malloc.

In this case, you want to explain root outside of main, node* root; and also then, later, and inside of main, do the assignment there, source = malloc(...);

You had the right idea, however you should do that in two steps.

If this answers her question, please click on the examine mark to accept. Let"s save up top top forum maintenance. ;-)


Just to add to this, ns don"t think you require root to it is in the dimension of 27 nodes, simply the size of one node. Moreover, every level the the trie must have an are for 27 characters, an ext than the is a waste of resources, so unless MAX is a #define because that 27, then reconsider the use dimension of your guideline arrays.


You need to log in to answer this question.

Not the prize you're looking for? Browse various other questions tagged pset5 .


site architecture / logo © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.11.5.40661

See more: What Is The An Ex Policeman Lost His Riddle Answer 2021, An Ex Policeman Riddle Answer (Solved)

trident-gaming.net stack Exchange works ideal with JavaScript permitted

your privacy

By clicking “Accept every cookies”, you agree stack Exchange deserve to store cookies on your maker and disclose details in accordance v our Cookie Policy.