//File: reverseString
//Author: Jesse D
//Date: Mar. 7, 2007
//
//Description: This program uses function to return the reversed value of
// an inputed character string. The result is printed to the screen.
//
//
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;
char* reverse(char a[], int size){
int j =0, i = size;
char *temp = new char[size];
//Reverse the characters of a and store them in temp.
while( i >= 0){
temp[j] = a[i-1];
j++;
--i;
}
return temp;
}
int main()
{
char word[100];
int i=0;
cout << "Enter a string to reverse: " << endl;
cin >> word;
// Count the characters.
while (word[i] != '\0'){
i++;
}
char *r;
r = new char[i];
// Find the reverse of the inputed word.
r = reverse(word, i);
//Print the reverse.
cout << "The reverse of " << word << " is " << r << endl;
return 0;
}