I'll take a run at explaining it. This is a very popular hash function for this pset and other uses.
It uses a seed value because changing the starting hash value, the seed value, has an effect on how many or how few hash collisions (different inputs producing the same hash as output) occur. For example, using a large prime number may produce less ...
The first big problems I see are in check(). Look at this line:
while(cursor->next != NULL)
This is going to result in every other node being skipped, among other anomalies. It should be checking cursor, not cursor->next. I'll let you figure out why. Next, there's the two free(cursor) statements in the check function. Even though you created a ...
The reason for the seg faults lies in check() It uses a do/while setup that checks whether temp is null after running the loop. If the bucket was empty and table[hashed] is NULL, then it's going to generate a seg fault. This is highly likely with a small dictionary. Use a standard while loop instead.
The next problem is that check() tries to hash whatever ...
node *checker = malloc(sizeof(node));
/* ... */
checker = hashtable[index];
means you allocate a new node, and then you throw away the only reference to that node, leaving this node as "definitely lost". There is no need to malloc in check. You copy pointers (memory addresses), not nodes. Same goes for the free, remove it, you might ...
char *word = NULL;
while (fscanf(dict, "%s", word) != EOF)
The problem lies with word. It's a pointer to NULL. Next, the fscanf does a read and stores it at NULL, the infinite bit bucket. In other words, it discards it.
Either space for the read has to be malloc'd and the address stored in word, or, a different approach, create a char array large enough ...
inline int hashValue(const char* word)
Not sure why you have inline there, but remove that and it should compile fine.
Secondly, looks like you changed the declaration of check. It needs to be
bool check(const char *word)
You can't change word, so you'll need to create a temporary char array to hold your lowercase version. Once you do that, then you ...
I would take into consideration everything that ronga said! It's a bad idea to create such a massive array to serve as a giant buffer, when all that you need is one small buffer to hold only one word at a time.
But to specifically address your question about how to pass the word in memory to the hash function, you can merely pass it a pointer to the ...
Lots of syntax errors.
The "not equal to" operator, !=, operates on two values or variables, comparing them. This statement has one value, EOF. The correct operator would be the not operator, !.
fscanf(dictionary, "%s", new_node -> word);
dictionary is a constant character string, the file name, not a file pointer. I'll leave it to you ...
Let's assume that your question has several typos. It should read
int hash = toupper(key)-'A';
Having said that, did you remember to add the two necessary includes for toupper()?
If you forgot ctype.h, it will definitely produce the error that you said.
If this answers your question, please click ...