Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions