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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.