Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

a. What happens to the labor demand curve? LOP8

Answered: 1 week ago

Question

=+26.14. 1 Show that y has no point masses if 2(t) is integrable.

Answered: 1 week ago