Question: Someone Help me with this I have Code but its not Running and Allocating memory is not my best I get confused with -> .

Someone Help me with this I have Code but its not Running and Allocating memory is not my best

I get confused with -> . & and all those symbols for memory.

THIS IS C++ btw

void kstrextend(kstring *strp, size_t nbytes)

Modifies an existing kstring, pointed to by strp, to be at least nbytes bytes long.

If strp->length was already nbytes or longer, does nothing. That is, this function will never reduce the length of a string, only increase it.

If nbytes is longer than the current length, this function should take the following steps:

Allocate a new array with the larger size.

Copy data over from the old array to the new one.

Fill the additional elements of the new array with null bytes ('\0').

Free the old array.

Make strp->data point to the new array.

Set strp->length to the new size.

Note: if you are using malloc() for memory allocation, the function realloc() will take care of steps 1, 2, and 4 with a single function call.

If there is an error allocating memory, this function should call abort() or throw an uncaught exception.

Note that this function takes a pointer to a kstring rather than taking a kstring by value. That means that changes you make to the strp->length andstrp->data members will be visible to the caller.

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!