Question: Operating Systems: I need to edit a C program to make it work. We are using threads, DO NOT EDIT THE CODE, just add what

Operating Systems: I need to edit a C program to make it work. We are using threads, DO NOT EDIT THE CODE, just add what is needed in the areas that have comments there (where is says TODO).

Spellchecker: Write a program that can read user input with one thread (the whole line) and determines if any of the words given was misspelled by running another thread to read the dictionary.txt and check if the given word is there. Make threads equal to the number of words given in the line. ///////////////////////////////// spellchecker.c ////////////////////////////////////////////////////

#include // printf()

#include // atoi(), exit(), ...

#include // strtok(), strcmp(), ...

#include // pthread types and functions

#define MAX_LINE_LENGTH 255

#define MAX_DICTIONARY_SIZE 202412

char dictionary[MAX_DICTIONARY_SIZE][MAX_LINE_LENGTH];

int dictionary_size = 0;

pthread_mutex_t dictionary_mutex;

void *check_word(void *arg) {

char *word = (char *) arg;

int i;

// TODO find in the dictionary if the word exists, if it does print %word% is spelled correctly.

// TODO if it does not then print %word% is spelled incorrectly.

pthread_exit(NULL);

}

int main() {

char line[MAX_LINE_LENGTH];

pthread_t thread;

FILE *dictionary_file = fopen("dictionary.txt", "r");

if (dictionary_file == NULL) {

printf("Error: cannot open dictionary file ");

exit(EXIT_FAILURE);

}

// TODO read and populate the dictionary with the contents of the file

fclose(dictionary_file);

printf("Enter a line of text: ");

// TODO get the user input using fgets until the user enters a single dot

// for every word create a thread that checks the spelling of that word.

pthread_exit(NULL);

}

/////////////////////////////// dictionary.txt ///////////////////////////////// * Text file containing most of the English dictionary *

Make in bold the areas that you edited so I know what you did to fix the code. Thank you. And no, I can't use comments because this website is trash, so just do the code correctly the first time please.

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!