Question: only work on dictionary.c implement the function c language |ifndef ENTRY_H Hdefine ENTRY_H / Nunber of bytes allocated for mord storage in each entry /


only work on dictionary.c
implement the function
c language
|ifndef ENTRY_H Hdefine ENTRY_H / Nunber of bytes allocated for mord storage in each entry / Hdefine WOPDBUFSZ 16 / * The naximum word length derived fron the buffer size */ Hdefine MAXWORDLEN (VORDBUFSZ = 1) struct dict_entry i char word[WORDBUFSZ]; / The word. Stored in struct for better cache locality. */ char *definition; / The definition. Dynanically allocated. * / struct dict_entry *next; / Linked list next pointer. / \}; struct dictionary i int size; / The number of words in the dictionary. // struct dict_entry list; / The head of the list of entries. / \}i fk * Allocate a new dictionary entry aith the given word and its definition. * The length of the mord should not exceed MAXMORDLEN (defined above). * NOTE: Do NOT directly assign the 'word' and 'definition' strings to the struct! * Copy then into the struct instead (and allocate buffer where needed). */ struct dict_entry *neilentry(const char *word, const char *definition); * Free a dictionary entry. / void free_entry(struct dict_entry *entry); /k * Insert a dictionary entry into a dictionary while keeping the dietionary * in sorted order. You nay assune there won't be any duplicates. / void dict_insert_sorted(struct dictionary *dict, struet dict_entry *entry); /k * Renove a word fron the dictionary. No-op if dictionary is enpty or * the mord does ont exist in the dictionary. /k * Print a word entry in the folloning format: * " * speech sound or series of speech sounds... * (The definition starts on a nee line with tao leading spaces.) */ void print_word(struct dict_entry *entry); * Print all the words in the dictionary. Each mord should be printed in * the sane format as the print_mord() function. There should be an empty * Line after each entry (inctuding the last one). / void print_dietionary(struet dictionary *diet); / * Print the entire list of words in the dietionary without their definitions. * Each word shoutd be printed on its own line. void print_word_List(struct dietionary diet); /k * Look up a word in the dietionary and return the corresponding dict_entry, * or NULL if the mord is not in the dietionary. / struct dict_entry *diet_loohup(struct dietionary *dict, const char *word); /k * Load a dictionary fron a formatted file. The expected fornat for * the dictionary file is that each line contains one word and its definition, * separated by a colon and a space (": "): * word: speech sound or series of speech sounds... */ struct dictionary *load_dietionary(const char *filenane); /k * Free the entire dictionary of words and the dictionary itself. */ Hendif // ENTRY_H - dictionary.c dictionary.h \#include stdio. h \#include \#include \#include "dictionary.h" f return NULL; // placeholder void free_entry (struct dict_entry *entry) f return; // placeholder \} void dict_insert_sorted(struct dictionary dict, struct dict_entry *entry) f return; // placeholder void dict_remove_word(struct dictionary dict, const char *word) f return; // placeholder struct dict_entry *dict_lookup(struct dictionary *dict, const char *word) f return NULL; // placeholder \} void free_dictionary(struct dictionary *dict) f return; // placeholder \} void print_dictionary(struct dictionary dict) return; // placeholder void print_word_list(struct dictionary dict) f return; // placeholder \} void print_word(struct dict_entry *entry) f return; // placeholder \} struct dictionary *load_dictionary (const char *filenane) f FILE *fp; char line = NULL; size_t Len =; ssize_t nread; struct dictionary dict; if ( (dict =nalloc( sizeof ( dict )))){ perror("nalloc"); return NULL; \} dict size =; dict list = NULL; if (Ifilename) \{ return dict; \} if (!(fp= fopen(filenane, "r"))) f perror("fopen"); return NULL; \} while (( nread =getline(&line,&len,fp))I=1){ char word = strtok(line, " " "); char definition = strtok (NULL," "); while ( definition ==1 ) definitiont+; struct dict_entry *entry = new_entry(word, definition); dict_insert_sorted(dict, entry); \} free(line); fclose(fp); return dict; \}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
