Question: Write a function ` delete _ present _ list ` to free all memory allocated for an array of structures containing dynamically allocated strings and

Write a function `delete_present_list` to free all memory allocated for an array of
structures containing dynamically allocated strings and return a null pointer.
Function Signature:c
struct present* delete_present_list(struct present* present_list, int num);
Structure Definition:
struct present {
char *present_name;
float price;
};
Sample Edge Cases:
Null Pointer for present_list:
When passed to the function, the present_list is NULL. The function should gracefully handle
this case by returning NULL immediately.
Zero Presents (num =0):
The num parameter is 0, indicating no presence in the list. The function should handle this
case without attempting to access or free any memory.
Null Pointers within present_list:
Some present_name pointers within the present_list array are NULL. The function
should check each present_name before attempting to free it.
Memory Allocation Failures (Hypothetical):
While this isn't typically part of a deletion function, consider what might happen if
present_name allocations had failed during the list's creation. This might require handling
NULL pointers within the array

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!