Hello,
I need to write a program that takes a string and reverses it via pointers. I have a function called Reverse and what it does is take to pointers (front and rear) and intializes them to the front and back of the char array respectively. Then what it does is one by one go through the char array and switches front with rear. Finally front++ and rear-- until they equal each other. The problem I am having is outputting new array. What am i doing wrong?
void Reverse(char entry[], int &length)
{
int i = 0, j = length - 1;
char *front, *rear;
char temp;
while (i != j)
{
*front = entry[i];
*rear = entry[j];
temp = *front;
*front = *rear;
*rear = temp;
i++;
j--;
}
for (int k = 0; k < length; k++)
{
cout << entry[k];
}
}