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 deletepresentlist to free all memory allocated for an array of
structures containing dynamically allocated strings and return a null pointer.
Function Signature:c
struct present deletepresentliststruct present presentlist, int num;
Structure Definition:
struct present
char presentname;
float price;
;
Sample Edge Cases:
Null Pointer for presentlist:
When passed to the function, the presentlist is NULL. The function should gracefully handle
this case by returning NULL immediately.
Zero Presents num :
The num parameter is indicating no presence in the list. The function should handle this
case without attempting to access or free any memory.
Null Pointers within presentlist:
Some presentname pointers within the presentlist array are NULL. The function
should check each presentname before attempting to free it
Memory Allocation Failures Hypothetical:
While this isn't typically part of a deletion function, consider what might happen if
presentname 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
