Question: Hey everyone, i need help making a function with this directions. C++ language. Thanks. Directions: Write a function declaration and definition for the char* function

Hey everyone, i need help making a function with this directions. C++ language.

Thanks.

Hey everyone, i need help making a function with this directions. C++

Directions: Write a function declaration and definition for the char* function allocCat. This function should take in as a parameter a const Words pointer (Words is a defined struct) The function should allocate exactly enough memory for the concatenation of all of the strings in the array passed in, then copy those strings, one after the other, into the newly allocated space. The original strings must remain unchanged. The function should return the pointer to the newly allocated space or a NULL pointer if no space was allocated The code below shows an example of how this function might be called. struct words int numberofWords; char theWords [ARRAY_SIZE] [FILENAME MAX]; typedef struct words Words; // alloccat prototype (declaration) goes here: // sample main shows how allocCat might be called int main (void) Words mywords = { ARRAY-SIZE, { "stuff", " and", " nonsense" } }; char* ful!String = NULL; int returnValue EXIT SUCCESS; fullstring = alloccat(&myWords ); //calls the function you write below if (ful ! String== NULL) // get out if memory not allocated fprintf (stderr, "Could not allocate memory " returnValue = EXIT FAILURE ; else puts (fullstring); free (fullString); // prints out the new string // releases memory getch ); return returnValue this sample code above would print out stuff and nonsense ! WARNING: The code given above is an example of how the function might be used. Do not try to use the sample code above in the function definition! The function has no ilo! Hint: This function will need to calculate the length of the strings passed in. It needs to be able to work with ANY STRINGS, not just those shown in the example char* allocCat(

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!