so I tried implementing the insert function, but everytime I try doing something with the Trie* given, the tests tell me "runtime error: meber access within null pointer of the type “struct Trie” ", so I guess the given Trie* is NULL. But even if I try to catch this case, the error appears. Is the function used anywhere else where I have to insert something?
okay I got it, it’s not the trie itself that makes the error appear, but when I try moving to the next node
Is there anything wrong in doing
trie = trie->next[*word - ‘a’] when trying to get to the node with the next letter of the word?
Do you actually check whether next[whatever] is NULL before assigning it?
Also if Trie* trie is your input you should be careful to not overwrite it with anything else during your insertion process. (i.e. after insert(trie, str) is called the pointer trie should still point to the root)
Have you tried debugging to see what goes wrong and at which place exactly?
I am also wondering, why you are using
*word - 'a', this is only going to work for the first character, unless you change the
yes, and if it’s not existend I used create()
yes but not enough I guess
Yes, I got a loop for the length of the word and I do change the pointer
Then there is theoretically nothing wrong with this assignment.
hm okay thanks, then I am going to go on debugging I guess
If you are in any way working with looking for the nullbyte character, check whether you check for ‘0’ or actually for the nullbyte character, which is ‘\0’ (with a backslash infront).
This might lead to the actual memory problem, because you are trying to access at an index of -97 or whatever.