I have been stuck on the load part of the speller exercise for the tries table. I have gone through a lot of the existing questions and come to the following code:
while (fscanf(file, "%s", word) != EOF)
{
// TODO
node *ptr=root;
for (int l=0; l<LENGTH+1; l++)
{
if (isalpha(word[l]))
{
// lower case:
word[l] = tolower(word[l]);
if (ptr->children[word[l]-'a']==NULL)
{
ptr->children[word[l]-'a']= malloc(sizeof(node));
}
ptr = ptr->children[word[l] - 'a'];
}
}
}
However, when I run through the code in the debug mode, I see that my ptr keeps getting reset after the line ptr = ptr->children[word[l] - 'a'] is run. is this expected? I was expecting the node ptr to be accumulating as the for loop continues... or in fact ptr here is only a temp one and really I should set up some other node?
ptr
keeps getting reset? what value is ptr reset to?