Question: In C Please dynamic memory allocation Using the following struct to store information about library members struct member{ int id; char * name; }; Using
In C Please dynamic memory allocation Using the following struct to store information about library members struct member{ int id; char * name; };
Using the following function to store new member names using dynamic memory allocation using member name and id. If not enough memory is available then exit the program struct student * create_member(int id, char * name); //name must be a valid string
//exit program if not enough memory is available
Next code a function to release the memory allocated to that member record which was created using create_member. Make sure that there is no memory leak. void release_mem(struct member * m);
//delete_member(m) frees the memory associated with the member record m // m must be a member record created using dynamic memory allocation
Then complete a boolean function to change name of a given member using malloc or realloc to get enough memory to store the name. If the name change is successful then return true. If there isn't enough memory the function must return false and leave the original name as is.
bool name_change(struct member * m, char * name_new);
//name_change changes the name given of member m to the name given by name_new using dynamic memory allocation
//name_new allocates the memory to hold the new name and must be a valid string
//requires m to be a vaild member created by create_member In the main functon, test all the functions using assert and strcmp. Create 5 records using create_member then test that name_change works.Then free the memory using release_mem. Finally explain in a couple of words how each of the functions work, then using big O explain the running time of create_member, release_mem and name_change applied to a member with a name of n length. For name_change assume that both member name and new name have n as the higher bound. We can also assume that malloc uses O(1) and realloc uses O(n) operations when applied to a memory block. (Please explain this part in detail so I can have clear understanding, I struggle with it big time)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
