Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Find.c #includefind.h char * lineptr [ MAX _ LINES ] ; int readlines ( ) { int len, nlines; char * p , line
Find.c
#include"find.h
charlineptrMAXLINES;
int readlines
int len, nlines;
charp lineMAXLEN;
nlines ;
whilefgetsline MAXLEN, stdin
len strlenline;
ifnlines MAXLINES p malloclen NULL
return ;
else
iflinelen
linelen ;
strcpyp line;
lineptrnlines p;
return nlines;
void errorint errorcode
printffind: fatal error Illegal usage. Error code: d Usage: s
errorcode, "find nxsrmcfp pattern";
exiterrorcode;
flags setflagsint argc, char argv
flags option
forint i ; i argc ;i
ifargvi
error;
forint j ; argvij;j
switchargvij
case n:case N:
option NUMBERED;
break;
case x:case X:
option EXCEPT;
break;
case s:case S:
option SORTED;
break;
case r:case R:
option REVERSED;
break;
case m:case M:
option MATCHED;
break;
case c:case C:
option CASE;
break;
case f:case F:
option FIRST;
break;
case p:case P:
option PARTIAL;
break;
default:
error;
return option;
int mainint argc, char argv
ifargc
error;
char pattern strdupargvargc ;
flags option setflagsargc argv;
ifoption & REVERSED && option & SORTED
error;
int nlines readlines;
ifoption & SORTED
quicksortlineptr nlines ;
char initial;
forint i ; i nlines;i
ifoption & NUMBERED
sprintfinitiald i ;
char firstoccurrence strstrwoptionlineptri pattern, option;
ifoption & EXCEPTfirstoccurrence NULL
printfss
initial, lineptri
return ;
Find.h
#include
#include
#include
extern charlineptr;
#define MAXLINES
#define MAXLEN
typedef enum
NUMBERED
EXCEPT
SORTED
REVERSED
MATCHED
CASE
FIRST
PARTIAL
flags;
char strstrwoptionchar haystack, char needle, flags option;
void quicksortcharstr int left, int right;
util.c
#include"find.h
static char strstrfullymatchedchar haystack char needle
char rv;
char paddedneedlestrlenneedle;
paddedneedle;
strcpypaddedneedle needle;
paddedneedlestrlenneedle;
paddedneedlestrlenneedle
ifstrcmpneedle haystack
return haystack
if strncmphaystack paddedneedle strlenneedle
return haystack;
if rv strstrhaystack paddedneedle NULL
return rv ;
paddedneedlestrlenneedle;
if rv strstrhaystack paddedneedle NULL &&
rvstrlenpaddedneedle
return rv ;
return NULL;
static void tolowerchar input
forint i ;i strleninput;i
inputi tolowerinputi;
char strstrwoptionchar haystack, char needle, flags option
ifoption & CASE
tolowerhaystack strduphaystack;
tolowerneedle strdupneedle;
ifoption & MATCHED
return strstrfullymatchedhaystack needle;
else
return strstrhaystack needle;
else ifoption & MATCHED
return strstrfullymatchedhaystack needle;
else
return strstrhaystack needle;
static void swapvoid v int i int j
void temp vi;
vi vj;
vj temp;
void quicksortcharstr int left, int right
int i last;
ifleft right
return;
swapstr left, left rightleft;
last left;
fori left ; i right;i
ifstrcmpstristrleft
swapstrlast, i;
swapstr left, last;
quicksortstr left, last;
quicksortstr last right;
My professor told me when I ask him for help and clarification he was traveling and couldnt and to reach out to a teachers assistant but they wont answer anyone in my class. I need help on this assignment I have given my code and dont know what the issue is
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started