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

In my C++ assignment I am supposed to swap two character arrays. I cannot use an

ID: 671394 • Letter: I

Question

In my C++ assignment I am supposed to swap two character arrays. I cannot use any libraries and it has to be done using pointers. Here is what I have so far:

void mySwap (char *a, char *b)

{

int aLength = myLength(a);

int bLength = myLength(b);

  

char temp = *a;

*a = *b;

*b = temp;

}

That will swap the first letter on each of them. I know I need some kind of loop to swap for the length of each of the character arrays which is why I have pulled the length of each array already.

Thanks for your help!

Explanation / Answer

void swap1(char **aptr, char **bptr)

{ char *temp = *aptr;

*aptr = *bptr;

*bptr = temp;

}   

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