how do i check the logic of this ... i have not yet implemented the hash function ... can i check for errors without doing this or it is impossible to check without the hash function...?
// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
{
// TODO
//sort them in the table by number of chars rather that alphabetically
//open dictionary in read mode
FILE *dic = fopen("dictionary", "r");
//check if file exists
if (dic == NUL)
{
return false;
}
char *dic_word[46];
//scan each word from the dictionary
while (fscanf(dic, "%s", dic_word) != EOF)
{
//create new node
node *n = malloc(sizeof(node));
if (n ==NULL)
{
return false;
}
//copy the word into the node
strcpy(n->word, dic_word);
n->next = NULL;
//hash the word (how many chars does it have)
int i = hash(dic_word);
//if no elements at the ith location`s list, insert node
if (table[i] == NULL)
{
table[i] = n;
}
//if there are other elements in the list, insert node in the front
else
{
n->next = table[i];
table[i] = n;
}
}
return true;
}