Question: Modify the C program is split into two source files and one header file. In this project, you are allowed to modify all parts of
Modify the C program is split into two source files and one header file. In this project, you are allowed to modify all parts of the program.
Put all functions related to operations on the list of guests into volunteer.c
Create a header file named volunteer.h that contains struct volunteer declaration and prototypes for the functions in volunteer.c The header file should enclose the contents of the header file in an #ifndef#endif pair to protect the file.
Put readline function in readline.c
Create a header file named readline.h that contains function prototype for readline function. The header file should enclose the contents of the header file in an #ifndef#endif pair to protect the file.
#include
#include
#include
#define MaxClrLength
#define InputFileName "supply.csv
#define OutputFileName "result.csv
#define MaxSupplyItems
#define MaxNameLength
struct supply struct to hold information
char nameMaxNameLength;
char colorMaxClrLength;
int quantity;
;
int compareconst void a const void b
const struct supply supplya const struct supply a;
const struct supply supplyb const struct supply b;
int namecmp strcmpsupplyaname, supplybname; compare name
if namecmp
return namecmp;
return strcmpsupplyacolor, supplybcolor; compare by color if names are the same
int readlineFILE file struct supply supplies read line function
int count ;
while fscanffile
d
suppliescountname, suppliescountcolor, &suppliescountquantity
count; reads line until eof and increment count
return count; Return total # of supplies
void WriteResultstruct supply result int n Function to write search results to an output file
FILE file fopenOutputFileNamew; File in write mode
if file NULL
printfError opening file.
; Error message if fails to open
return;
for int i ; i n; i Write supply info to output file
fprintffilessd
resultiname, resulticolor, resultiquantity;
fclosefile; Close the output file
int main
struct supply suppliesMaxSupplyItems; Array to store supplies from the input file
FILE file fopenInputFileNamer; Open input file in read mode
if file NULL
printfError opening file.
; Error message if file opening fails
return ;
int NumSupplies readlinefile supplies; Looks up supply information from the input file
fclosefile;
qsortsupplies NumSupplies, sizeofstruct supply compare; Sort supplies using quicksort
WriteResultsupplies NumSupplies; Write sorted supplies to the output file
return ;
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
