Question: Part 1. You will be implementing a dictionary structure (storing pairs key/value), and reading the user input to manipulate the structure. The commands implemented in
- Part 1. You will be implementing a dictionary structure (storing pairs key/value), and reading the user input to manipulate the structure. The commands implemented in that stage are put, get, and del. It will be important not to leak any memory in these functions.
- Part 2. You will add two more commands: clr, which clears the dictionary, and siz, which prints the size of the dictionary. Again, clr will have to make sure not to leak any memory. You will also implement a destructor for your dictionary object.




// Create a dictionary. dict_t* dict_create (); // Free a dictionary. void dict_destroy (dict_t* dic); // Put an element in a dictionary. key is case sensitive, val is a string. If // the key already exists, its value is updated. If val is NULL, the pair is // deleted. void dict_put (dict_t* dic, const char* key, const char* val); // Return the value associated with key, or NULL if none. char* dict_get (const dict_t* dic, const char* key); // Delete the pair associated with key. void dict_del (dict_t* dic, const char* key); // Return the size of the dict. size_t dict_size (const dict_t* dic); // Delete all elements in a dictionary. void dict_clear (dict_t* dic); // Apply fun to each pair key/val; arg is an extra argument passed to fun. void dict_apply (const dict_t* dic, const dict_apply_fun_t fun, void* arg);[main . c: In function 'dict_put' : main. c:29:8: error: 'dict_list_t' {aka 'struct dict_list'} has no member named 'value'; did you mean 'val' ? d->value = value; ANNAN val main. c:29:16: error: 'value' undeclared (first use in this function); did you mean 'val'? d->value = value; ANNAN val main. c:29:16: note: each undeclared identifier is reported only once for each function it appears in main. c:30:13: error: incompatible types when assigning to type 'struct dict_list *' from type 'dict_t' {aka 'struct dict'} d->next = *dict; main. c:31:11: error: incompatible types when assigning to type 'dict_t' {aka 'struct dict') from type 'dict_list_t *' {aka 'struct dict_list *'} *dict = d; main. c: In function 'dict_del' : main . c : 40:44: : error: 'dict_t' {aka 'struct dict'} has no member named 'next' for (ptr = dict; ptr != NULL; ptr = ptr->next) { main. c:41:23: error: 'dict_t' {aka 'struct dict'} has no member named 'key' if (stromp(ptr->key, key) == 0) main. c:42:23: error: 'dict_t' {aka 'struct dict'} has no member named 'value' return ptr->value; }}return NULL; main . c:42:20: error: 'return' with a value, in function returning void [-Werror] return ptr->value; }}return NULL; main . c:38:6: note: declared here void dict_del (dict_t* dict, const char* key) { ANNNNNNN main . c: 42:40: error: 'return' with a value, in function returning void [-Werror] return ptr->value; }}return NULL; ANNN main . c:38:6: note: declared here void dict_del (dict_t* dict, const char* key) { ANNNNNNN main. c: In function 'dict_size' : main . c: 48:9: error: expected expression before '->' token return->size; main . c: In function 'dict_clear' : main. c:52:3: error: unknown type name 'delete'; did you mean 'dev_t'? delete dict; dev_t main. c:52:10: error: 'dict' redeclared as different kind of symbol delete dict; main. c:51:26: note: previous definition of 'dict' was here void dict_clear (dict_t* dict) { NNNNNNNNANNN main . c:52:10: error: unused variable 'dict' [-Werror=unused-variable] delete dict; main. c: At top level: main. c:61:1: error: expected identifier or '(' before numeric constant 1, 1 main . c: In function 'dict_size' : main . c:49:1: error: control reaches end of non-void function [-Werror=return-type]#include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
