Question
Here's the project to be modified: #include #include #include #include #define NAME_LEN 30 struct equipment{ char type[NAME_LEN+1]; char description[NAME_LEN+1]; int quantity; struct equipment *next; };
Here's the project to be modified:
#include
#include
#include
#include
#define NAME_LEN 30
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);
void update(struct equipment *list);
void printList(struct equipment *list);
void clearList(struct equipment *list);
int read_line(char str[], int n);
/**********************************************************
* main: Prompts the user to enter an operation code, *
* then calls a function to perform the requested *
* action. Repeats until the user enters the *
* command 'q'. Prints an error message if the user *
* enters an illegal code. *
**********************************************************/
int main(void)
{
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 (;;) {
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(" ");
}
}
struct equipment *append_to_list(struct equipment *list)
{
struct equipment *q = (struct equipment *) malloc (sizeof(struct equipment));
printf("Enter type: ");
scanf("%s", q -> type);
printf("Enter description: ");
scanf("%s", q -> description);
printf("Enter quantity: ");
scanf("%d", &q -> quantity);
q -> next = NULL;
if(list == NULL)
list = q;
else
{
struct equipment *p = list;
while (p -> next != NULL)
p = p -> next;
p -> next = q;
}
return NULL;
}
void update(struct equipment *list)
{
char type[NAME_LEN + 1];
char description[NAME_LEN + 1];
int quantity;
printf("Enter type :");
scanf("%s", type);
printf("Enter description :");
scanf("%s", description);
printf("Enter quantity :");
scanf("%d", &quantity);
if (list == NULL)
{
printf("The list is empty ");
}
else
{
struct equipment *p = list;
int found = 0;
while(p!=NULL)
{
if (strcmp(p -> type, type) == 0 && strcmp(p -> description, description) == 0)
{
p -> quantity = quantity;
found = 1;
break;
}
p = p->next;
}
if (found == 0)
printf("List not found ");
else
printf("List updated ");
}
}
void printList(struct equipment *list)
{
if (list == NULL)
{
printf("The list is empty ");
}
else
{
struct equipment *p = list;
while(p!=NULL)
{
printf("Type: %s ", p -> type);
printf("Description: %s ", p -> description);
printf("Quantity: %d ", p -> quantity);
printf(" ");
p = p -> next;
}
}
}
void clearList(struct equipment *list)
{
if (list == NULL)
{
printf("The list is empty ");
}
else
{
struct equipment *p = list;
while (list != NULL)
{
p = list;
list = list->next;
free(p);
}
}
}
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;
}
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 players 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 readline function is in a separate file named readline.c. 4) Create a header file named readline. h that contains a prototype for the read line 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 circe. The makefile should co ntain 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_equip.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 roster Before you submit: 1. (part I) Compile with the following command and test with try_ equip gcc -Wall equipment.c readline.c group equip.c ./try equip 2. (part 2) Be sure your makefile contains the information necessary to build the roster program. Test your makefile: make group equip . group equiD 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 players 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 readline function is in a separate file named readline.c. 4) Create a header file named readline. h that contains a prototype for the read line 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 circe. The makefile should co ntain 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_equip.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 roster Before you submit: 1. (part I) Compile with the following command and test with try_ equip gcc -Wall equipment.c readline.c group equip.c ./try equip 2. (part 2) Be sure your makefile contains the information necessary to build the roster program. Test your makefile: make group equip . group equiDStep 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