Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the C programming language only, you will write a program that gets a pattern string from command- line arguments, receives multiple lines from the

In the C programming language only, you will write a program that gets a pattern string from command- line arguments, receives multiple lines from the standard input stream, and finally prints out the lines containing the pattern string. This must be done C only! No java

image text in transcribed
image text in transcribed
In this assignment, you will write a program that gets a pattern string from commandline arguments, receives multiple lines from the standard input stream, and finally prints out the lines containing the pattern string. 1 Program Command Line Arguments The program must support the following command-line arguments: - (10 points) -n: prints out the line numbers that contain the pattern string. Please note that line-numbering starts from 1. - (10 points) -x: prints ont the lines that do not contain the pattern string (or, excludes: the lines containing the pattern string) - (10 points) -s: prints out the lines in alphabetical order (default order is FIFO). - (10 points) -r: prints out the lines in the reverse order (the line that appears last in stdin will appear first in stdout). Please note that you mest make sure that user does not use 8 and r flags at the same time. If user wants to use both s and r flags, your program must get terminated after giving proper error messige to the user. - (10 points) -m: finds the pattern string only if it matches the whole word. You can assume that words are separated by white-space character only. - (5.points)-e ignores the case when finding the pattern string- - (15 points) -f: prints out the index of the first occurrence of pattern string in each line. Please note that you must make sure that user does not use - f and - x flags at the sume time. If user wants to use both f and x Alags your program mest get terminated after giving proper error message to the user. - (20 points )1 : partially prints out each line containing the pattern. To print out each line partially, you need to print the first 10 charactens of the line, followed by an ellipsis (...), followed by the first occurrence of the pattem followiod by abother ellipsis, followed by the lave five characters of the line. You can remove the first ellipsis if the pattern ovelaps the first 10 characters. Also, you can remove the second ellipeis if the pattern overlips the lest five characters. Addditionally, you ean print the whole sentence if the length of sentence is not greater than the pattern leguth plus 15. Please note that you must make sure that liser does not ise p and x flags at the sume time. If user wants to use both p and x flags, your program must got terminated aftur giving proper error meseage to the user. Your program must accept a sequence of lines followed by an EOF character from standard input stream. Here is an example of program input: I'm very interested in Computer Science This is a test statement Im in In-N-Out has great burgers in fact Last sentence In +D The output is given under different combinations of command-line arguments

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

1 . Television News channels importantance of our Life pattern ?

Answered: 1 week ago

Question

1. How is the newspaper help to our daily life?

Answered: 1 week ago