Question: myGrep with C .... Code that i have is below the images... Please help me do both part1 and the Extra credit !! My Code

myGrep with C .... Code that i have is below the images... Please help me do both part1 and the Extra credit !!myGrep with C .... Code that i have is below the images...Please help me do both part1 and the Extra credit !! MyCode so far ------------------------------------------------------------------------------------------------------------------------------------------------------- /* TODO: Included any required libraries. */ #include"wordList.h" /** * Adds a new occurrence to the end of alist. * tail - A pointer to the current tail of a

My Code so far -------------------------------------------------------------------------------------------------------------------------------------------------------

/* TODO: Included any required libraries. */

#include "wordList.h"

/**

* Adds a new occurrence to the end of a list.

* tail - A pointer to the current tail of a list, NULL if it's empty.

* line - The line in which the word occurs

* lineNum - The number of that line within the file

* wordNum - The position of that word within that line

*

* Returns a pointer to the new tail of the list.

*/

Node *addToTail(Node *tail, char *line, int lineNum, int wordNum) {

/* TODO: Implement this function. */

Node *newTail = (Node *)malloc(sizeof(struct Node)); /* we are creating a new node called newTail that we will have our old tail point to */

strcpy(newTail -> line, line); /* Now we want to copy the string line into the char line*/

newTail -> lineNum = lineNum; /* We need to access the part of our node structure and set the new line num*/

newTail -> wordNum = wordNum; /* We need to access the wordNum as well*/

newTail -> next = NULL; /* And here we set the next node from newTail to NULL */

if (tail == NULL) /* We check to see if we even have a tail */

{

*tail = *newTail; /* So now we must dereference tail to equal the dereference of newTail, since that is what we want our newTail to be*/

}

else

{

tail -> next = newTail; /* we want to set the "next" attribute to the newTail */

*tail = *newTail; /* Then we set the tail to be the newTail */

}

return tail; /* We then return the tail pointer */

}

/**

* Removes an occurrence from the beginning of a list.

* head - A pointer to the current head of a list, NULL if it's empty

* line - A pointer at which to store the removed line

* lineNum - A pointer at which to store the removed line number

* wordNum - A pointer at which to store the removed word number

*

* Returns a pointer to the new head of the list, NULL if it's (now) empty.

*/

Node *rmFromHead(Node *head, char *line, int *lineNum, int *wordNum) {

/* TODO: Implement this function. */

if (head == NULL) { return NULL; }

else {

strcpy(line, head -> line); /* Now we are copying the string of the current head.next to the line pointer , this will derefrence*/

*lineNum = head -> lineNum; /* *lineNum = head -> lineNum; We can see this as in the following way ... (*head).lineNum;

It is very important to understand that if we are using line ptrs

we are essentially going to make a temp pointer that will point to

head -> next ----- this is going to happen before we free the memory

of head , so that we may use this in order to set the next head.

temp is simply a pointer that we need to return. */

*wordnum = head -> wordNum;

Node *temp /* This is where we make a pointer called temp that is of type Node */

temp = head -> next;

void printList(Node *head) {

/* TODO: Implement this function. */

}

Assignment 8_Structs and Allocation Due: Friday, March 16th The Unix utility grep can be used to search a file for occurrences of a word. For this assignment, you'll use command line arguments, file I/O, and dynamic memory allocation to implement a similar program in C Deliverables: Demo none Write-up none Handin-myGrep.c, wordList.h, ordList.c (required) myGrep2.c, wordList2.h, wordList2.c (extra credit) GitHub Classroom Link: https://classroom.github.com/a/PEC928WB This is an individual assignment. You are not allowed a lab partner, nor are you allowed to work together even if you write your own c ode. Al Il your work must be your own Part 1: Ground Rules . You may not use any global or static local variables. - You must free any memory you allocate and close any files you open All of your code must compile on Cal Poly's Unix servers using gcc -Wal1 -Werror -ansi -pedantic Do not alter the given prototypes or header file, and do not write code in any files other than those specified above. Your functions will be tested individually Part 2: A List of Occurrences Begin by accepting the GitHub Classroom assignment: https://classroom.github.com/a/PEC928WB As your program reads through a given file for occurrences of a given word, t will store those occurrences in a linked list. wordList.h contains a definition of a linked list's node, along with the prototypes of three functions that operate on that linked list Begin by implementing the following function within wordList.c, which allocates, initializes, and adds a single node representing a single occurrence to the end of the linked list Node addToTail(Node *tail, char line, int lineNum, int wordNum); . Adds a new occurrence to the end of a list . Takes four arguments: .tail A pointer to the current tail of a list, NULL if it's empty lineThe line in which the word occurs lineNum The number of that line within the file wordNumThe position of that word within that line . Returns a pointer to the new tail of the list 1 of 5 Assignment 8_Structs and Allocation Due: Friday, March 16th The Unix utility grep can be used to search a file for occurrences of a word. For this assignment, you'll use command line arguments, file I/O, and dynamic memory allocation to implement a similar program in C Deliverables: Demo none Write-up none Handin-myGrep.c, wordList.h, ordList.c (required) myGrep2.c, wordList2.h, wordList2.c (extra credit) GitHub Classroom Link: https://classroom.github.com/a/PEC928WB This is an individual assignment. You are not allowed a lab partner, nor are you allowed to work together even if you write your own c ode. Al Il your work must be your own Part 1: Ground Rules . You may not use any global or static local variables. - You must free any memory you allocate and close any files you open All of your code must compile on Cal Poly's Unix servers using gcc -Wal1 -Werror -ansi -pedantic Do not alter the given prototypes or header file, and do not write code in any files other than those specified above. Your functions will be tested individually Part 2: A List of Occurrences Begin by accepting the GitHub Classroom assignment: https://classroom.github.com/a/PEC928WB As your program reads through a given file for occurrences of a given word, t will store those occurrences in a linked list. wordList.h contains a definition of a linked list's node, along with the prototypes of three functions that operate on that linked list Begin by implementing the following function within wordList.c, which allocates, initializes, and adds a single node representing a single occurrence to the end of the linked list Node addToTail(Node *tail, char line, int lineNum, int wordNum); . Adds a new occurrence to the end of a list . Takes four arguments: .tail A pointer to the current tail of a list, NULL if it's empty lineThe line in which the word occurs lineNum The number of that line within the file wordNumThe position of that word within that line . Returns a pointer to the new tail of the list 1 of 5

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!