Skip to content

Dictionary Documentation

Dawson Whitehead edited this page May 5, 2018 · 1 revision

About

We use a dictionary to be able to see whether words are spelled correctly. Dictionaries are implemented using a trie datastructure in this project. We need to support reading a list of words from a file and storing those as a dictionary for later use.

Quick Start

Creation and Deletion

To make a new dictionary, first assign a dictionary using dict_new.

To read a dictionary from a file, place the file in the same folder as the spellcheck application and run read_to_dict(filename, dictionary) with the filename as the file containing the dictionary and dict as the dictionary that needs the input.

To free all memory associated with a dictionary, run dict_free(dictionary).

Uses

To check if a string is in a dictionary, run in_dict(string, dictionary).

To add a string to a dictionary, run add_to_dict(string, dictionary).

All Functions

dict_new(): dict_t 
// Creates and initializes a dictionary. Returns a pointer to the dictionary

dict_init(dict_t*): int 
// Initializes a dictionary. Returns 0 on success, 0 on error

dict_free(dict_t*): int 
// Frees all memory associated with a dictionary. Always return 0

in_dict(char*, dict_t*): int 
// Checks if a string is in a dictionary. Returns 1 if yes, 0 if no, and -1 if there was an error

add_to_dict(char*, dict_t*): int
// Adds a word to a dictionary. Returns 1 on success, 0 if the word is already in the dictionary, and -1 on failure

read_to_dict(char*, dict_t*): int
// Parses a file and adds all words to the dictionary. Returns 1 on success, 0 if there is an error, and -1 on partial success

Clone this wiki locally