0
// Load function
bool load(const char *dictionary)
    {
     char word[LENGTH + 1];
     FILE *file = fopen("dictionary", "r");
    
     if (file == NULL)
     {
        printf("Couldn't open dictionary\n");
        return false;
     }
       while (fscanf(file, "%s", word) != EOF)
       {
           node *p = malloc(sizeof(node));
           if (p == NULL)
           {
               printf("Error allocating node");
               return NULL;
           }
           strcpy(p->word, word);
           p->next = NULL;
           word_count++;
    
           int hashed = hash(word);
    
           p->next = table[hashed]->next;
           table[hashed]->next = p;
        }
        return true;
    
    
    // Hash function
    // Hashes word to a number
    unsigned int hash(const char *word) // CREDIT: Dan Berstein http://www.cse.yorku.ca/~oz/hash.html
    {
        int hash = 401;
        int c;
    
        while (*word != '\0')
        {
            hash = ((hash << 4) + (int)(*word)) %N;
            word++;
        }
    
        return hash % N;
    }
    
    
    }
0

I think I found the reason the program is unable to load.

This line: FILE *file = fopen("dictionary", "r");

Should be: FILE *file = fopen(dictionary, "r");

You must log in to answer this question.

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