Every time I try to run speller.c I get an output of:
- Could not open dictionary
- Could not load dictionaries/large
I have a feeling that it is to do with the location of the dictionaries but I have moved them into the same directory, re downloaded the dictionaries, checked permissions and changed the definition of where to find the dictionaries. I now believe there is a problem with my code
This is my dictionary.c
/**
* Implements a dictionary's functionality.
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "dictionary.h"
int wordcount = 0;
char *word = NULL;
typedef struct node
{
char word[LENGTH + 1];
struct node *next;
}
node;
node *htable[HASHTABLE_SIZE];
int hashit(char *hashing)
{
unsigned int hash = 0;
for (int i = 0, j = strlen(hashing); i < j; i++)
{
hash = (hash << 2) ^ hashing[i];
}
return hash % HASHTABLE_SIZE;
}
/**
* Returns true if word is in dictionary else false.
*/
bool check(const char *word)
{
// TODO
return false;
}
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
bool load(const char *dictionary)
{
for (int i = 0; i < HASHTABLE_SIZE; i++)
{
htable[i] = NULL;
}
FILE *fp = fopen("dictionary", "r");
if (fp == NULL)
{
fprintf(stderr, "Could not open dictionary\n");
return false;
}
while (fscanf(fp, "%s", word) != EOF)
{
node *newnode = malloc(sizeof(node));
if (newnode == NULL)
{
fprintf(stderr, "Could not malloc new node\n");
return 3;
}
wordcount++;
int hashed = hashit(newnode->word);
node *top = htable[hashed];
if (top == NULL)
{
htable[hashed] = newnode;
}
else
{
newnode->next = htable[hashed];
htable[hashed] = newnode;
}
}
return false;
}
/**
* Returns number of words in dictionary if loaded else 0 if not yet loaded.
*/
unsigned int size(void)
{
// TODO
return 0;
}
/**
* Unloads dictionary from memory. Returns true if successful else false.
*/
bool unload(void)
{
// TODO
return false;
}