Advertisement
Guest User

Daisy's shiz

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.97 KB | None | 0 0
  1. // Implements a dictionary's functionality
  2.  
  3. #include <stdbool.h>
  4. #include <stdio.h>
  5. #include <cs50.h>
  6.  
  7. #include "dictionary.h"
  8.  
  9. //define structure for the dictionary as a trie (27 for the letters in the alphabet + ')
  10. typedef struct _dictionary
  11. {
  12.     bool is_word;
  13.     struct _dictionary *key[27];
  14. }
  15. loaded_dic;
  16.  
  17. // Returns true if word is in dictionary else false
  18. bool check(const char *word)
  19. {
  20.     // TODO
  21.     eprintf("%s", word);
  22.     return false;
  23. }
  24.  
  25. // Loads dictionary into memory, returning true if successful else false
  26. bool load(const char *dictionary)
  27. {
  28.     // open the dictionary file
  29.     FILE *dic = fopen(dictionary, "r");
  30.     // Check whether dictionary was opened, return false if not
  31.     if (dic == NULL)
  32.     {
  33.         printf("Could not open dictionary file %s\n", dictionary);
  34.         return false;
  35.     }
  36.  
  37.     // create a pointer for first
  38.     //loaded_dic *first = malloc(sizeof(loaded_dic));
  39.  
  40.     // Create buffer variable to hold the word
  41.     char *word = malloc(LENGTH + 1);
  42.  
  43.     // itterate over words from the file until the EOF
  44.     //for (char* = fgets(word, LENGTH, dic), i != NULL, i = fgets(word, LENGTH, dic))
  45.     while (fgets(word, LENGTH, dic) != NULL)
  46.     {
  47.         eprintf("%s\n", word);
  48.     }
  49.  
  50.  
  51.         // iterate through the word letter by letter, where letter = key (ASCII 97-122)
  52.  
  53.         //create temp pointer
  54.         //check if the temp pointer for that key is NULL
  55.             //if null, malloc another trie - check this isn't null
  56.             //move temp pointer
  57.         //else, move temp pointer
  58.  
  59.  
  60.         // when you get to the end of the word, set the struct is word
  61.  
  62.     // return true as EOF was hit
  63.     free(word);
  64.     return false;
  65. }
  66.  
  67. // Returns number of words in dictionary if loaded else 0 if not yet loaded
  68. unsigned int size(void)
  69. {
  70.     // TODO
  71.     return 0;
  72. }
  73.  
  74. // Unloads dictionary from memory, returning true if successful else false
  75. bool unload(void)
  76. {
  77.     // TODO
  78.     return false;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement