We changed our privacy policy. Read more.
9

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 ...


2

What's that rogue unload(); doing at the end of your main loop in load?


1

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 ...


1

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 ...


1

Your code 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 ...


1

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 ...


1

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 ...


1

Instead of a variable head, containing arbitrary value hashtable[0], use hashtable[hashed_number] (you might need to do the hashing a bit earlier)


1

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 ...


1

Lots of syntax errors. while (!=EOF) 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 ...


1

Let's assume that your question has several typos. It should read int hash = toupper(key[0])-'A'; Having said that, did you remember to add the two necessary includes for toupper()? #include <stdio.h> #include <ctype.h> If you forgot ctype.h, it will definitely produce the error that you said. If this answers your question, please click ...


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