Question
Using the struct and array creation function listed below, create a copy of the array using the function defition above Description typedef struct LonelyPartyArray {
Using the struct and array creation function listed below, create a copy of the array using the function defition above "Description"
typedef struct LonelyPartyArray {
int size; int num_fragments; int fragment_length; int num_active_fragments; int **fragments; int *fragment_sizes;
} LonelyPartyArray;
LonelyPartyArray *createLonelyPartyArray(int num_fragments, int fragment_length){ if( (num_fragments>0)&&(fragment_length>0) ){ LonelyPartyArray *createdArray; createdArray = (LonelyPartyArray *)malloc( sizeof(LonelyPartyArray) ); if(createdArray==NULL){ return NULL; } createdArray->fragment_length = fragment_length; createdArray->num_fragments = num_fragments; createdArray->num_active_fragments = 0; createdArray->size = 0; createdArray->fragments = (int ** )calloc(num_fragments,sizeof(int *)); if(createdArray->fragments==NULL){ free(createdArray); return NULL; } createdArray->fragment_sizes = (int*)calloc(num_fragments,sizeof(int)); if(createdArray->fragment_sizes == NULL){ free(createdArray->fragments); free(createdArray); return NULL;
---
LonelyPartyArray *cloneLonelyPartyArray(LonelyPartyArray *party);
Description: Dynamically allocate a new LonelyPartyArray struct and set it up to be a clone of party. The clone should have entirely new, separate copies of all the data contained within party. (For example, the clone should not simply refer to partys fragments. Instead, it should have entirely new copies of those fragments.)
If any calls to malloc() fail, free any memory that this function dynamically allocated up until that point, and then return NULL.
Output: If party is non-NULL, print the following: -> Successfully cloned the LonelyPartyArray. (capacity:
Returns: If party is NULL, or if any calls to malloc() fail, simply return NULL. Otherwise, return a pointer to the newly allocated lonely party array.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started