// Diego Martinez                         CSC5             Chapter 10, P.588, #2
/*******************************************************************************
* DISPLAY REVERSE STRING
* ______________________________________________________________________________
* This program asks the user to enter a string. A function is used to display
* the contents of the C-string backward.
*
* Computation is based on the Formula:
*
*      Display characters from the end of the string to the beginning
*
* ______________________________________________________________________________
* INPUT
*
*      User string
*
* OUTPUT
*
*      String displayed backward
*
*******************************************************************************/

#include <iostream>
#include <cstring>
using namespace std;

// Function prototype
void backwardString(const char *);

int main()
{
    // Variable declaration
    char userString[100];

    // User input
    cout << "Enter a string: ";
    cin.getline(userString, 100);

    // Function call
    cout << "The string backward is: ";
    backwardString(userString);

    cout << endl;

    return 0;
}

// Function definition
void backwardString(const char *str)
{
    int length = strlen(str);

    // Display string backward
    for (int i = length - 1; i >= 0; i--)
    {
        cout << *(str + i);
    }
}