I think this relates to my understanding (or lack of) of pointers. I have 3 errors for the following code -- this is just inside my while statement. Both root and current are defined as nodes and malloced:
int index = 0;
// defines constant to use in calculating index
const int ltr = 'a';
root = NULL;
current = NULL;
// checks each character in word one by one
for (int i =0; i < strlen(word); i++)
{
// ' is at index 26
if (word[i] == '\'')
{
index = 26;
}
// determines index number of letters in words based on lower case ascii mod with base
else
{
index = word[i] % ltr;
}
// if not yet any letters checked
if (root == NULL)
{
// allocate space for node
children[index] = malloc(sizeof(node));
// root now has child pointer -- index corresponds to alphabet
root->children[index];
// the current node is now equivalent to the current node
current = children[index];
}
// if already started (ie Root now points to something other than NULL) and
// there is already something at child[index]
else if (children[index] != NULL)
{
// current node holds the pointer at child[index]
current->children[index];
// and the child[index] pointer gets assigned to current
// child[index] currently points potentially to NULL
current = children[index];
}
// but if child[index] does not yet contain pointer to next node
// need to malloc space
else
{
children[index] = malloc(sizeof(node));
current->children[index];
current = children[index];
}
}
// end of word reached
current->is_word = true;
And here are the three errors I get (I know I don't have the line numbers above, but hope it makes sense):
dictionary.c:78:37: error: expression result unused [-Werror,-Wunused-value]
root->children[index]; ~~~~~~~~~~~~~~ ~~~~~^
dictionary.c:87:40: error: expression result unused [-Werror,-Wunused-value]
current->children[index]; ~~~~~~~~~~~~~~~~~ ~~~~~^
dictionary.c:97:40: error: expression result unused [-Werror,-Wunused-value]
current->children[index]; ~~~~~~~~~~~~~~~~~ ~~~~~^