Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C only please !!! Implement the following function to allocate an array of pointers to Employee structs with a length determined by its integer

In C only please!!!

Implement the following function to allocate an array of pointers to Employee structs with a length determined by its integer parameter:

Employee ** createEmployeeArray(int maxLength)

Then implement the following function to add a new employee into the array:

int addNewEmployee(Employee *p, Employee **array)

The return value should equal the index of the location in the array that points to the newly-added employee. Note, however, that there is a potential error condition if the array is full and the new employee cant be added (this doesnt involve a failed call to malloc because this function doesnt need to allocate any memory). How can you inform the user of that error condition given the above prototype?

Lastly, you will, of course, need to provide the user with a function to free the employee array:

void * freeEmployeeArray(Employee **array)

This function should correctly free all memory allocated in the createEmployeeArray function, and it will always return NULL so the user can call it in the following way:

empArray = freeEmployeeArray(empArray);

Why would the user want to do this? Well, because the assignment will set empArray to NULL so that it cant later be referenced accidently after its been freed.

Okay, so what makes this prelab a bit more complicated than it might appear at first glance? Well, when a new employee is added, how will the function know the next available index location to store the pointer? And how will it check whether the array is full so that it can inform the user that the employee cant be added? Somehow addNewEmployee will need to know the index of the next available location, and it will need to know the length of the array, but how can it know that when its only passed an array? If only there were a way to associate information like that with the array when its created...

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_2

Step: 3

blur-text-image_3

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions