roster.c #include <stdio.h> #include <string.h> #include <ctype.h> #define NAME_
ID: 3760346 • Letter: R
Question
roster.c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define NAME_LEN 30
struct player{
int number;
char first_name[NAME_LEN+1];
char last_name[NAME_LEN+1];
struct player *next;
};
struct player *append_to_list(struct player *roster);
void find_player(struct player *roster);
void printList(struct player *roster);
void clearList(struct player *roster);
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 player *team_roster = NULL;
printf("Operation Code: a for appending to the roster, f for finding a player"
", p for printing the roster; q for quit. ");
for(;;){
printf("Enter operation code: ");
scanf(" %c", &code);
while (getchar() != ' ') /* skips to end of line */
;
switch (code) {
case 'a': team_roster = append_to_list(team_roster);
break;
case 'f': find_player(team_roster);
break;
case 'p': printList(team_roster);
break;
case 'q': clearList(team_roster);
return 0;
default: printf("Illegal code ");
}
printf(" ");
}
}
struct player *append_to_list(struct player *roster){
//add code here and remove the return NULL; statement
return NULL;
}
void find_player(struct player *roster)
{
//add code here
}
void printList(struct player *roster){
//add code here
}
void clearList(struct player *roster)
{
//add code here
}
int read_line(char str[], int n){
int ch, i = 0;
while (isspace(ch = getchar()))
;
str[i++] = ch;
while((ch = getchar()) != ' '){
if (i < n)
str[i++] = ch;
}
str[i] = '';
return i;
}
Explanation / Answer
Try This Code to complete this Question
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.