Advertisement
jrhauser11

Speller load function

Jul 29th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. // Loads dictionary into memory, returning true if successful else false
  2. bool load(const char *dictionary)
  3. {
  4.     FILE *file = fopen(dictionary, "r");
  5.     if (!file)
  6.     {
  7.         return false;
  8.     }
  9.     char* word = malloc(LENGTH);
  10.     word = NULL;
  11.     while (fscanf(file, "%45s", word) != EOF)
  12.     {
  13.         node *n = malloc(sizeof(node));
  14.         n->next = NULL;
  15.         if (!n)
  16.         {
  17.             return false;
  18.         }
  19.         strcpy(n -> word, word);
  20.         int index = 0;
  21.         index = hash(word);
  22.         n->next = table[index];
  23.         table[index] = n;
  24.         free(n);
  25.         SIZE += 1;
  26.     }
  27.     return true;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement