Question: Project 9 code: #include #include #include #include #define NAME_LEN 30 //variables and functions struct equipment{ char type[NAME_LEN+1]; char description[NAME_LEN+1]; int quantity; struct equipment *next; };

 Project 9 code: #include #include #include #include #define NAME_LEN 30 //variables

Project 9 code:

#include

#include

#include

#include

#define NAME_LEN 30

//variables and functions

struct equipment{

char type[NAME_LEN+1];

char description[NAME_LEN+1];

int quantity;

struct equipment *next;

};

struct equipment *append_to_list(struct equipment *list);

//voids

void update(struct equipment *list);

void printList(struct equipment *list);

void clearList(struct equipment *list);

int read_line(char str[], int n);

int main(void)

{

//printf/scanf for output/input

char code;

struct equipment *e_list = NULL;

printf("Operation Code: a for appending to the list, u for updating an equipment"

", p for printing the list; q for quit. ");

//for and while loops

for (;;) {

printf("Enter operation code: ");

scanf(" %c", &code);

while (getchar() != ' ') /* skips to end of line */

;

switch (code) {

case 'a': e_list = append_to_list(e_list);

break;

case 'u': update(e_list);

break;

case 'p': printList(e_list);

break;

case 'q': clearList(e_list);

return 0;

default: printf("Illegal code ");

}

printf(" ");

}

}

//function

struct equipment *append_to_list(struct equipment *list){

struct equipment *temp = (struct equipment *)malloc(sizeof(struct equipment));

//input

printf(" Enter The Equipment type : ");

scanf("%s",&temp->type);

printf(" Enter The Description of Equipment : ");

scanf("%s",&temp->description);

printf(" Enter The Quantity of Equipment : ");

scanf("%d",&temp->quantity);

if(list == NULL){

list = temp;

temp->next = NULL;

return list;

}

//loop

struct equipment *tt = list;

while(tt != NULL){

if(strcmp(tt->description,temp->description) == 0 && strcmp(tt->type,temp->type) == 0){

printf(" Equipment Already Exists !!! ");

return list;

}

if(tt->next == NULL){

break;

}

tt = tt->next;

}

tt->next = temp;

temp->next = NULL;

return list;

}

void update(struct equipment *list)

{

if(list == NULL){

return;

}

int tquan = 0;

//input with allocated memory

struct equipment *temp = (struct equipment *)malloc(sizeof(struct equipment));

printf(" Enter The Equipment type : ");

scanf("%s",&temp->type);

printf(" Enter The Description of Equipment : ");

scanf("%s",&temp->description);

printf(" Enter The Quantity to update : ");

scanf("%d",&tquan);

struct equipment *tt = list;

while(tt != NULL){

if(strcmp(tt->description,temp->description) == 0 && strcmp(tt->type,temp->type) == 0){

tt->quantity = tt->quantity + tquan;

free(temp);

return;

}

tt = tt->next;

}

printf(" Not Found Equipmnet : ");

free(temp);

}

void printList(struct equipment *list){

struct equipment *p = list;

//while loop

while(p != NULL){

printf(" Type = %s Description = %s Quantity = %d",p->type,p->description,p->quantity);

p = p->next;

}

}

void clearList(struct equipment *list)

{

//variables inlisting

struct equipment *temp = list;

struct equipment *prev = NULL;

while(temp != NULL){

prev = temp;

temp = temp->next;

free(prev);

}

free(list);

}

int read_line(char str[], int n)

{

int ch, i = 0;

while (isspace(ch = getchar()))

;

str[i++] = ch;

while ((ch = getchar()) != ' ') {

if (i

str[i++] = ch;

}

str[i] = '\0';

return i;

}

//End of program

1. (60 points) Modify Project 9 program so that the program is split into three source files and two header files 1) Put all functions related to operations on the list of equipments into equipment.c 2) Create a header file named equipment.h that contains struct equipment declaration and prototypes for the functions in equipment.c. The header file should enclose the contents of the header file in an # ifndef # endif pair to protect the file. 3) Put the read line function is in a separate file named readline.c. 4) Create a header file named readline.h that contains a prototype for the read 1line function. The header file should enclose the contents of the header file in an #ifndef-#endif pair to protect the file. 5) group equip. c contains the main function. 6) Include appropriate header files in the source files 2. (40 points) Write a makefile to build the roster program on student cluster. The makefile should contain the following rules: 1) Build readline.o by compiling readline.c 2) Build equipment.o by compiling equipment.c 3) Build group equip.o by compiling group equip.c 4) Build group equip by linking readline.o, equipment.o, and group eauip. O Each rule should include the name of the target file, dependencies among files, and the command to be executed. The makefile should name the executable file for the program group equip

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!