Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write two functions that read user input into a struct nba _ player variable, and print out each player in a more readable format. The

write two functions that read user input into a struct nba_player variable, and print out each player in a more readable format. The functions should have the following prototypes:
nba_player ReadStruct(FILE *infile);
void PrintStruct(nba_player pl);
Loop through this ReadStruct()-> PrintStruct() loop until you receive fake NBA player with name "List Endington". Your output should match the following example, as well as the included test cases (which will be piped to stdin but for reference are also stored in nba/):
Player 1>1,DeMar DeRozan ,32,76,76,2743,774,1535,.504,50,142,.352,724,1393,.520,.521,520,593,.877,56,336,392,374,68,24,181,178,2118
Player: DeMar DeRozan
Age: 32
G (GS): 76(76)
FG / FGA (FG%): 774/1535(50.4%)
3P /3PA (3P%): 50/142(35.2%)
2P /2PA (2P%): 724/1393(52.0%)
FT / FTA (FT%): 520/593(87.7%)
TRB - ORB, DRB: 392-56,336
AST, STL, BLK, TOV: 374,68,24,181
Player 2>2,Nikola Vuevi,31,73,73,2418,546,1154,.473,104,331,.314,442,823,.537,.518,92,121,.760,142,662,804,236,70,71,136,181,1288
Player: Nikola Vuevi
Age: 31
G (GS): 73(73)
FG / FGA (FG%): 546/1154(47.3%)
3P /3PA (3P%): 104/331(31.4%)
2P /2PA (2P%): 442/823(53.7%)
FT / FTA (FT%): 92/121(76.0%)
TRB - ORB, DRB: 804-142,662
AST, STL, BLK, TOV: 236,70,71,136
Player 3>13,List Endington ,0,0,0,0,0,0,.000,0,0,.000,0,0,.000,.000,0,0,.000,0,0,0,0,0,0,0,0,0
#include
#include
typedef struct nba_player_s {
int Rk; // Rank (we're not sorting, so more of an ID for us)
char Player[128]; // Player name - include first and last name so ("%s %s") and then convert to Player[]
int Age; // Age
int G; // Games played
int GS; // Games started
int MP; // Minutes played
int FG; // Field goals (baskets)
int FGA; // Field goal attempts (shots)
float FGP; // Field-goal percentage
//...add the rest
} nba_player;
nba_player ReadStruct(FILE *infile);
void PrintStruct(nba_player player);
nba_player ReadStruct(FILE *infile){
nba_player pl;
char first[128], last[128]; // You'll need to grab these separately and then convert to .Player
// Data format:
//Rk,Player,Age,G,GS,MP,FG,FGA,FG%,3P,3PA,3P%,2P,2PA,2P%,eFG%,FT,FTA,FT%,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS
// Don't try to fit this all on one line!
fscanf(infile,"%d,%s %s ,"
"%d"
,
&pl.Rk, first, last,
&pl.Age
);
// Process first and last into pl.Player. sprintf() is fine for this.
//sprintf(pl.Player,...)
return pl;
}
void PrintStruct(nba_player pl){
printf("
Player: %s
", pl.Player);
printf(" Age: %d
", pl.Age);
printf(" G (GS): %d (%d)
", pl.G, pl.GS);
printf(" FG / FGA (FG%%): %d /%d (%2.1f%%)
", pl.FG, pl.FGA, 100*pl.FGP);
return;
}
int main(void){
int ID =1;
while (1){
printf("Player %d>", ID++);
//nba_player player = ReadStruct(stdin);
// What is our exit / break condition?
//PrintStruct(player);
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions