Question: Write a complete C program that will parse an input file and search for occurrences of a word pattern. The program will output the total
Write a complete C program that will parse an input file and search for occurrences of a word pattern. The program will output the total number of occurrences and all of the lines with the word pattern in it.
1. Command-Line Arguments:
Read in the command-line arguments and verify that there are three parameters: the program name, an input file that is the name of the file you will be working with, and the word pattern that you are searching for. If the number of parameters is incorrect, print out a usage message and terminate the program.
2. File I/O:
Open the file that was given as a command-line argument to your program. Then, read through the file and print the following information: the total number of lines in the file, the number of characters in the longest line of the file, and the longest line of the file.
3. Pattern Matching (i.e., grep):
Create a data structure that holds all of the information for each occurrence of a word pattern. For example, it should hold the line number and the contents of the line it occurs on. Print all of the information (i.e., the line number and the contents of the line it occurs on), including the total number occurrences of the word pattern.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
