2

I'll pick one. // Adds word to list void append(const char *word, node *list) What is this meant to do? I guess you pass a word and the pointer to the list head, and expect a new node to be added to the list. But how would you handle an empty list (which is usually represented by NULL)? For that, the usual solution is to either return the new list head (...


1

this is problematic fread(dict, 1, 999999, fopen(dictionary, "r")); you can read one word at a time with fscanf, keep reading it in a loop until fscanf returns EOF.


1

Your code is returning true if the first few characters form a valid word, ignoring the rest. The code if (current->is_word == true) { return true; } should be after the loop, when current is at the node representing the full word.


1

Remove the quotation marks around cursor->word. "cursor->word" is a pointer to some read-only location where exactly those characters ({'c', 'u', 'r', ...}), together with a null terminator, are stored. When strcpy tries to copy to that location, you get this nice segfault. cursor->word instead is the word member of the struct cursor points to. ...


1

if (i == l - 1) { cursor->is_word = true; } would have to go behind cursor = cursor->children[n]; because otherwise you target the wrong node. I would place the cursor->is_word after the inner loop, when the cursor is on that node anyway. Similarly, your check checks one ...


1

You have a "small" problem in check function, you actually go through the entire hash table without finding any match. What happens if strcasecmp () is zero? Why do you keep moving forward in the hash table? Why do you return a true rogue at the end of the function? Think, if strcasecmp () == 0, we return true, otherwise we continue checking, the code would ...


1

I took a very quick glance at it and see this: if (strcmp(word, wordcheck->word)) { return true; } This tells me that you've assumed that strcmp returns true/false. It does not. If the strings are identical, it returns 0, which evaluates as false. If the strings are different, it will return either a positive or a ...


1

Your size function shouldn't call the load function.


1

No, not at all. You're conflating two different var names to be the same variable. Let's look at the code: // Returns true if word is in dictionary else false bool check(const char *word) { ... if strcasecmp(cursor-> word, tword) !=0) cursor= cursor-> next; The variable tword is indeed derived from the variable word. But, this word is the name ...


1

What's n meant to represent? Your recursive function is looping from 0 to n to unload the children, but n isn't the number of children, N is.


1

You're on the right track. The problem is definitely within the hash function. I added a printf statement to print every word being checked to find out which word was triggering the seg fault. The culprit is a'n't. So, looking back at your hash function, there's a big oversight. What happens when the second or third letter is an apostrophe? Right now, ...


1

This has to be one of the most unique syntax errors I've seen in a while! You get today's award for something almost never seen! ;-) Let's look at one of the lines that are causing the problem: strcpy (new_node → word, word); Now, look very closely at the arrow, → This is a single character, a special character. It is NOT a dash - followed by ...


1

Here's the main issue that's blocking your progress: if (ptr -> word == wordt) Your goal is obviously to see if the words are the same. Unfortunately, this will compare addresses in memory, not strings. You need to use strcmp() or strcasecmp(). The latter might make it possible to eliminate some other code, but that's up to you. ;-) [EDIT] I had ...


1

The result of the comment discussion as an answer. I still have no idea why the IDE would time out, I am guessing valgrind had a hell of a job counting all the occasions where you read from uninitialised memory. Turns out the nodes malloced in load were not initialised. That could be done by something like (adjust variable names as needed) node *new_node =...


Only top voted, non community-wiki answers of a minimum length are eligible