Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include find. h extern char * strstr _ w _ option ( char * haystack, char * needle, flags option ) ; extern void

#include "find. h"
extern char* strstr_w_option(char* haystack, char* needle, flags option);
extern void quicksort(char*v[], int left, int right);
char *lineptr[MAX_LINES];
int readlines(){
int len, nlines =0;
char *p, line [MAX_LEN] ;
while (fgets(line, MAX_LEN, stdin)){
len = strlen(line);
if (nlines s= MAX_LINES || malloc(len +1Hi,
I'm working on a C program that reads multiple lines of input, searches for a pattern provided via command-line arguments, and supports several flags to modify the output. However, I'm encountering issues with two specific flags:
-s Flag (Sorting): When using the -s flag to sort the lines alphabetically, the program outputs duplicate lines and sometimes causes a segmentation fault.
-p Flag (Partial Print): The -p flag should print lines containing the pattern in a shortened format with ellipses. However, the output is not as expected and doesn't handle ellipses correctly.
Below is the relevant code for handling these flags. Could you please help me identify and fix the issues?
Issues:
Segmentation Fault with -s Flag:
When using the -s flag, the program outputs duplicate lines and sometimes causes a segmentation fault.
Partial Print with -p Flag:
The -p flag should print lines containing the pattern in a shortened format with ellipses. However, the output is not as expected and doesn't handle ellipses correctly.
Example Outputs:
Command: ./find -s in input.txt
Input:
Im very interested in Computer Science
This is a test statement
Im in
In-N-Out has great burgers in fact
Last sentence In
Expected Output:
Im in
Im very interested in Computer Science
In-N-Out has great burgers in fact
Command: ./find -p in input.txt
Expected Output:
Im very...in...ience
Im in
In-N-Out h...in... fact
image text in transcribed

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

Students also viewed these Databases questions

Question

Discuss the concept of risk and how it might be measured.

Answered: 1 week ago

Question

Define learning and list at least three learning principles

Answered: 1 week ago