Computer Science, asked by aswinigadamadugu, 4 months ago

implent a simple foot ball league program in c​

Answers

Answered by sachchu438
0

Explanation:

You are confused on how to store the playsrs. You have created a PLAYER struct, but you never use it. Instead, you insist that players must be a single string.

But it should work like this: You have n teams. Ecah team has m players. All team info is stored in your ´TEAMstruct. All player info is stored in yourPLAYERstruct. Because a team is made up of players, there should be aPLAYER` entry in your struct:

typedef struct {

char name[25];

char surname[25];

int number;

} PLAYER;

typedef struct {

char nameofteam[25];

int numberofplayers;

PLAYER *players;

} TEAM;

Then, when you read players, you read the bare team info in readteam. But you don't read anything about individual players there, because you delegate that to readplayer. Of course, the pointer you pass to that function must be that for a player, not one for a team:

void readplayer(PLAYER * pi)

{

printf("name:");

scanf("%s", pi->name);

printf("surname:");

scanf("%s", pi->surname);

printf("number of player:");

scanf("%d", &pi->number);

}

void readteam(TEAM * pt)

{

int i;

printf("name of team:");

scanf("%s", pt->nameofteam);

printf("number of players in team:");

scanf("%d", &pt->numberofplayers);

pt->players = calloc(pt->numberofplayers, sizeof(*pt->players));

for (i = 0; i < pt->numberofplayers; i++) {

printf("Player %d:\n", i + 1);

readplayer(pt->players + i);

}

}

Your cast to (char *) hides the warning about incompatible types. You should cast only when you know what you're doing. In this simple program, you don't need casts.

In your original code, there are warnings about "implicit declarations". These concern your copy and length functions. (By the way, what's wrong with strlen and strcpy?) You should move these functions to the top so that they are declared before they are called. ALternatively, provide prototypes at the beginning of your code or in a header file, which you #include at the top. (But now that you read into PLAYER structs, these functions are no longer needed.)

Similar questions