Question: I need to make a program that searches for every occurrence of a word within a file and store that information about each occurrence in

I need to make a program that searches for every occurrence of a word within a file and store that information about each occurrence in a linked list to be printed out. Below I have my linkedList code and header. Also below is some specs. Thank you!

________________________________________________________________________________

This is the .c linked list with functions

#include "wordList.h"

#include

#include

#include

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

{

Node *temp = (Node*)malloc(sizeof(Node));

strcpy(temp->line, line);

temp->lineNum = lineNum;

temp->wordNum = wordNum;

temp->next = NULL;

if (tail == NULL)

return temp;

else

tail->next = temp;

return temp;

return 0;

}

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

{

if (head == NULL)

return NULL;

strcpy(line, head->line);

*lineNum = head->lineNum;

*wordNum = head->wordNum;

if (head->next == NULL)

return NULL;

else

head = head->next;

return head;

return 0;

}

void printList(Node *head)

{

Node *temp = head;

while (temp != NULL)

{

printf("Node: -line: %s -lineNum: %d -wordNum: %d ", temp->line, temp->lineNum, temp->wordNum);

temp = temp->next;

}

return;

}

________________________________________________________________________________________________________________

This is header file

#define MAXLINE 101 /* The maximum length of a line, plus one. */

/**

* Represents a node in a linked list of word occurrences.

*/

typedef struct Node {

char line[MAXLINE]; /* The line in which the word occurs */

int lineNum; /* The number of that line within the file */

int wordNum; /* The position of the word within that line */

struct Node *next; /* The next node in the list */

} Node;

Node *addToTail(Node *, char *, int, int);

Node *rmFromHead(Node *, char *, int *, int *);

void printList(Node *);

I need to make a program that searches for every occurrence of

Part 3: Command Line Arguments and File I/O Develop a program that accepts, as command line arguments, a word and the name of a file. This program should search for every occurrence of that word within that file, storing information about each occurrence in a linked list so that they can be printed out later Additionally, your program should find the longest line in the file (regardless of whether or not it contains the specified word) and count the number of lines in the file Hint: Develop incrementally. Begin by making sure you can open a file, then read and echo each of its lines. You can use fgets to read single line from a file and strtok to iterate over the words in a line.] Requirements: Write your program in a file named "myGrep.c" .Before it begins its search, your program must verify and echo its command line arguments. . Your string comparisons may be case-sensitive. . You may assume that no line (or word) will be longer than 100 characters. . You may not make any assumptions about how many times the word occurs in a line or in the file . You must read through the file exactly once . You must store each occurrence of the word in a linked list, using the functions in wordList.c and the definitions in wordList.h . Store the line in which the word occurs . Store the number of that line within the file. Store the position of the word within that line. Both the lines in the file and the words in a line are numbered from 0 . You must free any memory that you dynamically allocate

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!