Question: /**************************************************************************** * dictionary.h ***************************************************************************/ #ifndef DICTIONARY_H #define DICTIONARY_H #include //Returns true if word is in dictionary else false. bool check(const char* word); // Loads dictionary

/**************************************************************************** * dictionary.h ***************************************************************************/ #ifndef DICTIONARY_H #define DICTIONARY_H #include //Returns true if word is in dictionary else false. bool check(const char* word); // Loads dictionary into memory. Returns true if successful else false. bool load(const char* dictionary); //Returns number of words in dictionary if loaded else 0 if not yet loaded. unsigned int size(void); //Unloads dictionary from memory. Returns true if successful else false. bool unload(void); #endif // DICTIONARY_H

-----------------

/**************************************************************************** * dictionary.c * Implements a dictionary's functionality. ***************************************************************************/ #include #include #include #include #include #include "dictionary.h" unsigned int wordLoaded = 0; typedef struct node{ bool is_word; struct node* children[27]; } node; node* root; //Returns true if word is in dictionary else false. bool check(const char* word) { node* current = root; int i = 0; while (word[i] != '\0') { char input = word[i]; if (word[i] == '\'') { input = 'z' + 1; } int newnum = tolower(input) - 'a'; if (current->children[newnum] != NULL) { current = current->children[newnum]; i++; } else { return false; } } if (current->is_word == true) { return true; } return false; } //Loads dictionary into memory. Returns true if successful else false. bool load(const char* dictionary) { FILE* dict = fopen(dictionary, "r"); if (dict == NULL) { return false; } root = malloc(sizeof (node)); char c = 0; //char from dict node* current = NULL; while (fgetc(dict) != EOF) { //go back 1 byte of the cursor fseek(dict, -1, SEEK_CUR); // Set the pointer to the root current = root; for (c = fgetc(dict); c != ' '; c = fgetc(dict)) { // Check for apostrophes if (c == '\'') { // Set it to one past the highest letter, z c = 'z' + 1; } // Check if the character exists in the trie if (current->children[c - 'a'] == NULL) { // If the character does not exist, malloc a new node current->children[c - 'a'] = malloc(sizeof (node)); // go to the new node current = current->children[c - 'a']; } else { // go to the node that is already present current = current->children[c - 'a']; } } current->is_word = true; wordLoaded++; } fclose(dict); return true; } // Unloads dictionary from memory. Returns true if successful else false. bool freeNode(node* thisNode) { for (int j = 0; j < 27; j++) { if (thisNode->children[j] != NULL) { freeNode(thisNode->children[j]); } } free(thisNode); return true; }

bool unload(void) { return freeNode(root); }

-----------------

/**************************************************************************** * speller.c * Implements a spell-checker. ***************************************************************************/ #include #include #include #include #include "dictionary.h" #undef calculate #undef getrusage double calculate(const struct rusage* b, const struct rusage* a); int main(int argc, char* argv[]) { // try to open text char* text = (argc == 3) ? argv[2] : argv[1]; FILE* fp = fopen(text, "r"); if (fp == NULL) { printf("Could not open %s. ", text); unload(); return 1; } // prepare to report misspellings //printf(" MISSPELLED WORDS "); // prepare to spell-check int index = 0, misspellings = 0, words = 0; char word[LENGTH+1]; // spell-check each word in text for (int c = fgetc(fp); c != EOF; c = fgetc(fp)){ // allow only alphabetical characters and apostrophes if (isalpha(c) || (c == '\'' && index > 0)){ // append character to word word[index] = c; index++; } // we must have found a whole word else if (index > 0) { // terminate current word word[index] = '\0';

// update counter words++;

// check word's spelling getrusage(RUSAGE_SELF, &before); bool misspelled = !check(word); getrusage(RUSAGE_SELF, &after); // print word if misspelled if (misspelled) { //print to a standard out }

// prepare for next word index = 0; } }

}

---------------------

Please edit the 3 C programs above so that is works with the prompt below. Remove all the unnecessary parts of the code. Add to code as well. Make sure the program runs. Use the .txt files below. Show output!!

word.txt contains the words below each on a new line in alphabetical order

an

be

coals

colliers

I

Gregory

mean

well

~~~~~~~~~~~~~

RomeoandJuliet.txt contains

Gregory, on my word well not carry coals. No, for then we should be colliers. I mean, an we be in choler, well draw.

~~~~~~~~~~~~~~~~~

  1. You will need to create TWO C programs (.c) . And create ONE header file (.h).
  2. Please comment all the files.
  3. First program- You will need to insert the words in word.txt into a dictionary trie. This trie should allow a caller to insert words to a trie and search the trie to find if a given word matches (case insensitive search) any stored word in the trie.
  • Basically put word.txt in a dictionary trie
  • Take into account the 26 letters and apostrophe ( ). It is also case insensitive.
  1. Second program- Next test your dictionary trie implementation by performing spell checks on all words read from RomeoandJuliet.txt.
  • Basically, in this code you will use check to see if the words in RomeandJuliet.txt is spelled the same as in word.txt. If a word in RomeandJuliet.txt is not in word.txt then it is considered misspelled.
  • Search the dictionary trie. If a word is in the trie then it is correct.
  1. Make a header file!!
  2. Please read in the two text files!!!
  3. Print the misspelled words to standard out. You can capture standard out to a file using the > and a filename. Please show how to do this in command line. The misspelled words should be exactly how they were in the Romeo and Juliet book.
  4. Each misspelled word should be on a new line.
  5. The words below are misspelled because they are not in word.txt.
  6. Misspelled words are

on

my

word

not

carry

No

for

then

we

should

we

in

choler

draw

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!