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: , fragments: ) This output should not include the quotes or angled brackets. Terminate the line with a newline character, . is the maximum number of integers this LPA can contain (num_fragments * fragment_length). is simply num_fragments. Note that in testing, we will never create a lonely party array whose capacity would be too large to store in a 32-bit int. If party is NULL, or if any calls to malloc() fail, this function should not print anything to the screen.

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

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!