Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C. NEED HELP in everything. Thank you. For this project we will continue on t

ID: 3779206 • Letter: I

Question

In C. NEED HELP in everything. Thank you.

For this project we will continue on the path of reading text the user provides. This time the text will be in a file. We no longer want to road 80 character chunks, instead we want to road in indviduaJ words, stop out any punctuation, and store the words, and the sentences in structures that will we dynamically create. The structures that we want you to use are defined in the file proj4structs.h, and are shown below: typedef struct words *wordPtr; struct words {char *theWord; int size; int orig_position; wordPtr next;}; typedef struct sentence *sentPtr; struct sentence {wordPtr firstWord; int numberwords; sentPtr next;}; Each structure will be used to create a linked list. So we will have a linked list of sentences, so we can have as many sentences as necessary. Each sentence will be a linked list so each sentence can have as many words as needed. Goal 1 is to prompt the user for a filename and read in the text from the file. stripping out punctuation other than apostrophes/hyphens/dashes {., ! O " $ %^& "()::"}, and populate/create the linked lists for the sentences and words within each sentence Goal 2 is to keep track of the original position of where the word was in each sent once (so we can rebuild the sentences later if needed). and than sort the words in the sentence by the first character of each word and update the linked Goal 3 is to store all of the sorted information in an output file. filename should be provided by the user output file should be organized as: sentence 1 information first sorted word information from sentence 1 second sorted word from sentence 1 last sorted word from sentence 1 sentence 2 information first sorted word information from sentence 2 Grading: 10 points reading in a word at a time from the file 10 points removing punctuation 10 points dynamically creating the word linked list(s) 10 points dynamically creating the sentence linked list 10 points sorting the words linked list(s) 10 points fie I/O and appropriate error checking for files 05 points not destroying/modifying the input file in any way 35 points are for style per

Explanation / Answer

#include #include #include typedef struct ListNode { char* word; struct ListNode *next; } ListNode; typedef struct List { ListNode *head; ListNode *tail; } List; List* build_list(char* fileName) { FILE* file = fopen(fileName, "r"); assert(file != NULL); List* list = malloc(sizeof(List)); assert(list != NULL); list->head = NULL; list->tail = NULL; char c; int word_size = 1; char* word = malloc(word_size); int word_count = 0; while ((c = fgetc(file)) != EOF) { assert(!ferror(file)); while (c != ' ' && c != EOF) { if (word_count == word_size) { word_size += 1; word = realloc(word, word_size); assert(word != NULL); } word[word_count++] = c; c = fgetc(file); assert(!ferror(file)); } word = realloc(word, word_size + 1); word[word_size] = ''; ListNode *node = malloc(sizeof(ListNode)); assert(node != NULL); node->next = NULL; node->word = word; if (list->head == NULL) { list->head = node; list->tail = node; } else { list->tail->next = node; list->tail = node; } if (c == EOF) break; word_count = 0; word_size = 1; word = malloc(word_size); } free(word); assert(!ferror(file)); return list; }