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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.