Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Implements a dictionary's functionality
- #include <stdbool.h>
- #include <stdio.h>
- #include <cs50.h>
- #include "dictionary.h"
- //define structure for the dictionary as a trie (27 for the letters in the alphabet + ')
- typedef struct _dictionary
- {
- bool is_word;
- struct _dictionary *key[27];
- }
- loaded_dic;
- // Returns true if word is in dictionary else false
- bool check(const char *word)
- {
- // TODO
- eprintf("%s", word);
- return false;
- }
- // Loads dictionary into memory, returning true if successful else false
- bool load(const char *dictionary)
- {
- // open the dictionary file
- FILE *dic = fopen(dictionary, "r");
- // Check whether dictionary was opened, return false if not
- if (dic == NULL)
- {
- printf("Could not open dictionary file %s\n", dictionary);
- return false;
- }
- // create a pointer for first
- //loaded_dic *first = malloc(sizeof(loaded_dic));
- // Create buffer variable to hold the word
- char *word = malloc(LENGTH + 1);
- // itterate over words from the file until the EOF
- //for (char* = fgets(word, LENGTH, dic), i != NULL, i = fgets(word, LENGTH, dic))
- while (fgets(word, LENGTH, dic) != NULL)
- {
- eprintf("%s\n", word);
- }
- // iterate through the word letter by letter, where letter = key (ASCII 97-122)
- //create temp pointer
- //check if the temp pointer for that key is NULL
- //if null, malloc another trie - check this isn't null
- //move temp pointer
- //else, move temp pointer
- // when you get to the end of the word, set the struct is word
- // return true as EOF was hit
- free(word);
- return false;
- }
- // Returns number of words in dictionary if loaded else 0 if not yet loaded
- unsigned int size(void)
- {
- // TODO
- return 0;
- }
- // Unloads dictionary from memory, returning true if successful else false
- bool unload(void)
- {
- // TODO
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement