Question: The function allocates memory for one player but it do not returns correct value when memory allocation fails, so I can fix it? /* This

The function allocates memory for one player but it do not returns correct value when memory allocation fails, so I can fix it?

/* This function allocates memory for a player_t pointer variable. Inputs: player_p_p - memory location of a player_t pointer variable nplayers - number of players that memory needs to be allocated for Return: 0 - success 1 - failed to allocate memory Post: After the function has been called, *player_p_p will point to freshly allocated memory if malloc was successful. Otherwise *player_p_p will point to NULL. */

int allocate_memory(player_t** player_p_p, long int nplayers) { player_p_p = ( player_t ** )malloc( nplayers * sizeof( player_t *)); if(player_p_p == NULL ) return 0; return 1;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!