Advertisement
Guest User

size issues

a guest
May 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.10 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.     while (fgets(word, LENGTH, dic) != NULL)
  45.     {
  46.         eprintf("%s\n", word);
  47.         int size = (sizeof(word)/sizeof(char));
  48.         eprintf("%i\n", size);
  49.         // iterate through the word letter by letter, where letter = key (ASCII 97-122)
  50.         for (int i = 0; i > sizeof(word); i++)
  51.         {
  52.             eprintf("%c   ", word[i]);
  53.             eprintf("\n");
  54.         }
  55.  
  56.  
  57.  
  58.  
  59.         //create temp pointer
  60.         //check if the temp pointer for that key is NULL
  61.             //if null, malloc another trie - check this isn't null
  62.             //move temp pointer
  63.         //else, move temp pointer
  64.  
  65.  
  66.         // when you get to the end of the word, set the struct is word
  67.  
  68.     }
  69.  
  70.     // return true as EOF was hit
  71.     free(word);
  72.     return false;
  73. }
  74.  
  75. // Returns number of words in dictionary if loaded else 0 if not yet loaded
  76. unsigned int size(void)
  77. {
  78.     // TODO
  79.     return 0;
  80. }
  81.  
  82. // Unloads dictionary from memory, returning true if successful else false
  83. bool unload(void)
  84. {
  85.     // TODO
  86.     return false;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement