Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I fix this? /* This function initialises each field of one playet_t stru

ID: 3742255 • Letter: H

Question

How can I fix this?

/*
This function initialises each field of one playet_t struct.
Inputs:
  player_p - memory location of the player_t variable. player_p must have been
    allocated memory using allocate_memory before calling this function.
  nplayers - number of players that memory needs to be allocated for
Post:
  After the function has been called, the age field of *player_p will be the
  input age, and wickets field of *player_p will be the input wickets.
*/

void init_player(player_t* player_p, int age, int wickets)
{  
player_p = ( player_t * )malloc( sizeof(player_p) );

player_p->age = age;

player_p->wickets = wickets;

}

Explanation / Answer

You need to call this function after you have allocated memory for player_t variable using allocate_memory() function. This function should not allocate memory again as it has been already allocated using allocate_memory() function. You just need to initialize values to player_p.

/*****DO NOT ALLOCATE MEMORY AGAIN AS IT HAS BEEN ALREADY ALLOCATED by allocate_memory()****/

Reach me out in comments if you need further help on this question. And please try to upload full question with supporting code as it will help us understand your problem better. Thank you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote