Sometimes you just have to walk away from the computer and clear your head.
The solution came to me as I was cooking breakfast this morning.
You have to pass it two pointers. One to the start and one to the end.
Do the swap, increment the start, decrement the end and pass them back.
Code:
/* prototypes */
void RecursiveReverse(char *ptrA, char *ptrB);
//call in main
RecursiveReverse(Array2, (Array2 + (strlen(Array2) - 1)));
/* Reverse the contents of a char array using recusion
Input: a pointer to a char array and a pointer to the end of that array
Output: the contents of the array in reverse order
*/
void RecursiveReverse(char *ptrA, char *ptrB)
{
char temp; //needed for the swap
char *pStart; //pointer to start of array
char *pEnd; //pointer to end of array
pStart = ptrA;
pEnd = ptrB;
if(pStart >= pEnd) // base_case if the pointers meet or overlap we're done
{
return;
}
else //we want to swap
{
temp = *pStart; //perform the swap
*pStart = *pEnd;
*pEnd = temp;
pStart++; //increment the start position
pEnd--; //decrement the end position
RecursiveReverse(pStart, pEnd); //recursive call with the new pointer values
}
}
It works great! Thanks to everyone who gave advice and tried to help.