Question: consider the following incomplete c program that receives multiple lines from stdin, sort them alphabetically, and print them all out in the sorted order. Complete
consider the following incomplete c program that receives multiple lines from stdin, sort them alphabetically, and print them all out in the sorted order. Complete the program so that it allows the user to enter an optional commandline argument i when running the program to ignore the case when sorting the input lines. The default behavior should sort in a casesensitive manner
#include
#include
#include
#define MAXLINES
#define MAXLEN
char lineptr$$lbrack$$MAXLINES$$rbrack$$;
int readlinesvoid
char line$$lbrack$$MAXLEN$$rbrack$$;
int nline ;# of lines
whilefgetslineMAXLEN, stdin
int len strlenline;
ifline$$lbrack$$len$$rbrack$$
n
line$$lbrack$$len$$rbrack$$
;
len;
lineptr$$lbrack$$nline$$rbrack$$
malloclen sizeofchar;
iflineptr$$lbrack$$nline$$rbrack$$
heap is full, cannot allocate memory!
return ;
lineptr$$lbrack$$nline$$ rbrack$$ line;a
lternative: lineptr$$lbrack$$nline$$rbrack$$
strdupline;
return nline;
void writelinesint len
forint i ; i len;i
printfs
lineptr$$lbrack$$i$$rbr
ack$$;
lineptr$$lbrack$$nline$$rbrack$$ line;a
lternative: lineptr$$lbrack$$nline$$rbrack$$
strdupline;
return nline;
void writelinesint len
forint i ; i len;i
ack$$;
printfs
lineptr$$lbrack$$i$$rbr
int comparestringsconst void first, const voi
d second
returns a negative int if first second
returns a positive int if first second
returns otherwise!
const char firststringpointer const c
harfirst;
const char secondstringpointer const
charsecond;
return strcmpfirststringpointer, second
stringpointer;
int comparestringsignorecaseconst void firs
t const void second
ignores case
const char firststringpointer const cha
rfirst;
const char secondstringpointer const
charsecond;
return strcasecmpfirststringpointer, seco
ndstringpointer;
int mainint arqc,
argv$$$$
int numberoflines, casesensitive ;
if
casesensitive strcmpargv$$lbrack$$
argv$$$$
int numberoflines, casesensitive ;
ifl
casesensitive strcmpargv$$lbrack$$
$$rbrack$$i: ;
ifnumberoflines readlines
printfError: cannot store input stream
in the memory!
;
return ;error code for low memory
s;
printf# of lines: d
numberofline
qsortlineptrsizetnumberoflines, size
ofchar
case sensitive
:
;
writelines
;
forint i ; i numberoflines;i
lineptr$$lbrack$$i$$rbrack$$;deallocate me
mory
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
