I wrote the load code for pset5 which compiles but when I execute speller.c it says "Could not load dictionary". I have used both my own dictionary text file and the dictionary at home/cs50/pset5/dictionaries/large.
This is really driving me crazy. My code is below. Any help would be greatly appreciated.
Thanks!
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
bool load(const char* dictionary)
{
int hashdex = 0;
//open dictionary file
FILE* fptr = fopen(dictionary, "r");
if(fptr == NULL)
{
printf("Could not load %s\n", dictionary);
return false;
}
//make new node
node* newNode = malloc(sizeof(node));
if(newNode == NULL)
{
printf("Out of heap memory.\n");
fclose(fptr);
return false;
}
while((fscanf(fptr, "%s", newNode->entry)) != EOF)
{
hashdex = hash_it(newNode->entry);
if(table[hashdex] == NULL)
{
newNode->next = NULL;
table[hashdex] = newNode;
}
//collision, add to the beginning
else
{
newNode->next = table[hashdex]->next;
table[hashdex]->next = newNode;
}
}
free(newNode);
fclose(fptr);
return true;
}