0

I'm running this program on a small dictionary and a small text sample. I think that loading the dictionary is working correctly. But how can I know for sure?

When I implement the load and check portions of the program, all words are returned misspelled.

When you look at the LOAD portion of the program, does it look like it is behaving correctly?

Thank you. It is all beginning to look like word salad to me.

bool check(const char *word) {
node *traveler = NULL;          //define a traveler to check for valid words
traveler = hashtable[hash(word)];
while (traveler != NULL)        //while still travelling across a word
{
    if (strcasecmp(traveler -> word, word) == 0)                            //check if letters match with compare strings strcasecmp
    {
        return true;
        free(traveler);
        //break;
    }
    else
    {
         traveler = traveler -> next; 
    }

}
return false;
free(traveler); }

Thank you. I've removed the free(traveler; line. I'm still not certain of how to check if the small dictionary is loading correctly. This is the code that I have for it:

// Insert words into hash table, populating process LOAD dictionary
while (fscanf(file, "%s", word) != EOF)
{

    if (new_node == NULL)                    // check success of malloc
    {
        unload();
        return false;
    }
    else
    {
        strcpy(new_node -> word, word);      //copy a word into 
        location = hash(word);              //what is this doing?
        new_node -> next = NULL;

        //Increment words_in_dictionary count to check that we are hitting the while loop 
        words_in_dictionary++;
    }

    if (hashtable[location] != NULL)
    {

        new_node -> next = head;
        hashtable[location] = new_node;
        printf("a new node was added \n");

    }
    else
    {

       new_node -> next = head;
       head = hashtable[location];      //I moved this down from line 85, does that make sense?
       hashtable[location] = new_node;
       printf("a different new node was added\n");
    }

}
0

You're lucky that none of the free(traveler); is ever executed (because return leaves the function before free is called), those nodes are still in use!

Does your hash function return same value regardless of case? Like would "hello" and "HeLlO" return same hash? If it does, your mistake is probably in load. You could then edit your load code into the question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .