Now, when creating a new node I use these lines to initialize them

node* temp = malloc(sizeof(node));

// initialize node
for(int i = 0; i < 27; i++)
    temp->children[i] = NULL;

//if at end of word
if(j == dIndex -1)
    temp->is_word = true;
    temp->is_word = false;

Is there a way to do this, especially setting all the children to zero, better?

Something like this?

temp->children = {0,0,0,0,0,0...,0}


To initialize an array with an initialization list, you must do that in the same statement that declares this array as follows

int arr[] = {1, 2, 3, 4, 5};

Since your array is a member of a struct, unfortunately, you can't use an array initialization list. Your way of doing it is absolutely one of the best ways. However, there is a function named memset (declared in string.h) that fills a number of bytes of a memory area with a value. You may execute

man memset

in the terminal for more information about this function!

You must log in to answer this question.

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