Well. Pset5 is a pain so far, but I'm a masochist so no problem there.
I think my logic is okay, but I have a problem with naming my nodes. I can't seem to come up with a way to name my nodes differently. This may seem blurry, but let me paste in part of my code for better understanding:
// iterates through the dictionary
for (int s = fgetc(dic); s != EOF; s = fgetc(dic))
{
if (s != '\n' && reset == 0)
{
s = s - 'a';
if (root -> path[s] == NULL)
{
node* node1 = malloc(sizeof(node));
root -> path[s] = node1;
}
reset++;
}
else if (s != '\n' && reset > 0)
{
s = s - 'a';
if (node1 -> path[s] == NULL)
{
node* node2 = malloc(sizeof(node));
node1 -> path[s] = node2;
}
reset++;
}
else
{
// currentnode -> is_word = true;
reset = 0;
}
}
Logic of this according to me
So what I'm trying to do there is the following:
I'm trying to get every word from the dictionary character by character, thus iterating through the whole file.
If the character is the first character of a word, then I check if in my root node that pointer 'space' in the array is NULL. If it is, I malloc a new node, and put a pointer to it from the root node.
If the character isn't the first char, then I check the same thing, except this time not with the root node, but rather the next node (node1). and here I think is where the problem lies
If the character being read by fgetc is newline, then I reset my counter, so I know a new word is coming, and indicate, that a word has ended (I know I need to refine this).
In summary: I have no idea how I could increase the nodecount (so afetr node1 comes a node 2, a node3 etc..)
Any ideas or hints? I think I smell that my logic is faulty in some way, but can't seem to see how.
Edit: Edited a bit cause I modified some var names.