I typed in the command window './speller texts/cat.t' The window print out 'Could not load dictionaries/large.' I've made all the 'return false' in load comments. I don't understand why it can still return false.

// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
    // Initialize hash table
    for (int i = 0; i < N; i++)
        hashtable[i] = NULL;

    // Open dictionary
    FILE *file = fopen(dictionary, "r");
    if (file == NULL)
        //return false;

    // Buffer for a word
    char word[LENGTH + 1];

    // Insert words into hash table
    while (fscanf(file, "%s", word) != EOF)
        // TODO

        // create node
        node *new_node = malloc(sizeof(node));
        if (new_node == NULL)
            printf("could not malloc a new node.\n");
            //return false;
        // copy the word into node
        strcpy(new_node->word, *word)
        new_node->next = NULL;
        // call upon hash function
        int ind = hash(new_node->word);
        // link the node to the list
        // first, point the pointer to where the first pointer point
        new_node->next = hashtable[ind];
        // second, point the pointer to the new node
        hashtable[ind] = new_node->next;
        // with every create node, keep track of size
    // Close dictionary

    // Indicate success
    return true;

I've also made sure the dictionaries files are in the same dir as speller.c, dictionary.c and tried to hard-code the path. Nothing seems to work so far. Any help will be greatly appreciated. Thanks.

#define DICTIONARY "~/pset5/speller/dictionaries/large"

This is probably not what you want to hear, but this sounds like the program can't find the dictionary. Working from the directory that contains the speller executable file, there needs to be a dictionaries subdirectory that contains the dictionaries large and small. (case sensitive could be playing a part.)

Next, the dictionary file has to be there and need to be intact. Have you checked this?

And, of course, if you've altered the main file, speller.c or speller.h, that can cause issues. Perhaps you should delete them and re-download the originals?

  • I went back and checked. It turned out I've speller.c in both pset4 and pset5. I've been editing the one in pset4 while compiling the one in pset5. I don't know how I can miss that. Thank you so much! – CTK2019 Feb 22 '20 at 3:17
  • Yeah, I figured it was something like that. Glad you solved this. If this answered your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-) – Cliff B Feb 22 '20 at 16:24

You must log in to answer this question.

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