Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COMPUTER SCIENCE, i have a simple C function that i would like to help to how to

ID: 3666470 • Letter: C

Question

COMPUTER SCIENCE, i have a simple C function that i would like to help to how to write it out.

void kstrcat(kstring *destp, kstring src)

Concatenates str onto the end of *destp. First extends *destp to be long enough to hold the contents of both strings, by calling kstrextend(). Then copies the contents of src into the dest

So, for example, if we execute the following code:

Now a should have length 12, and the contents "helloworld".

Note that this function takes a pointer to the destination kstring. That means that changes you make to the destp->length and destp->data members will be visible to the caller.

Note: Remember to save the original length of *destp before calling kstrextend(). Otherwise, you won't know where to copy src's data to!

Explanation / Answer

void kstrcat(kstring *destp, kstring src){
   int lenDest= strlen(destp);
   int lenSrc = strlen(src);
  
   destp=(char*)realloc(destp,lenDest*sizeof(char));
     
   int i = 0;
   while(src[i] !=''){
       destp[i+lenDest+1] = src[i];
       }
   destp[i+lenDest+1] = '';
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote