Complementary task for topic: 7
M Nemeth · 2023-08-29 15:21:04.625218'
DStrings+Struct: Simple Dictionary 1.
DStrings+Struct: Simple Dictionary 1.
HARD!
Main goal:
Create a C program that simulates a simple dictionary application. The program should allow the user to add new words and their meanings to the dictionary and search for the meanings of existing words. The word and its meaning will be stored as dynamic strings in a dynamic structure using dynamic memory allocation.
First task:
> Create a DicitonaryEntry struct to hold two Dstrings (the word and the meaning)
> Create a function to clear the buffer (we may need it later), as shown before
> Declare a Dictonary in the main
Hint: > The type of a Dstrin is just char*
> The buffer is cleared if all chars ening but including wiht \n is read
> The array of Dictionary entries is a dictionary
Solution
#include
#include
#include
typedef struct {
char* word;
char* meaning;
} DictionaryEntry;
void clearInputBuffer() {
int c;
while ((c = getchar()) != '\n' && c != EOF) {}
}
int main() {
int wordCount = 0;
DictionaryEntry* dictionary = NULL;
return 0;
}
Explanation
This is an empty dinamic array: We do not know how many entrities will be there.