// Andres Guzman CSC5 Chapter 10, P. 588, #2
/******************************************************************************
*
* REVERSE DICTIONARY WORD
* ____________________________________________________________________________
* Program function will accept a c-string as an argument and output the
* entered string in reverse.
*
* Computation:
*
* Function will compute using a "strlen" command and a for loop
* ____________________________________________________________________________
*
* INPUT
*
* SIZE = Array size of characters
* word = entered c-string
*
* OUTPUT
*
* reverse = Entered input reversed
*
******************************************************************************/
#include <iostream>
#include <cstring>
using namespace std;
void reverse(char *a); //Function Prototype
int main()
{
const int SIZE = 1000; //Array Size Based on the Longest English Word
char word[SIZE]; //Array of Characters
//
//Input Prompt
cout << "Enter a Word: ";
cin.getline(word, SIZE);
reverse(word); //Function Call and output
return 0;
}
/*******************************************************************************
* Adding Definition to function. This function will calculate the total length
* of the string and then using total, output each character from highest
* subscript element to lowest, outputting the character in reverse.
******************************************************************************/
void reverse(char *a)
{
int charnumber = strlen(a); //Stores the string length to variable
cout << "\nWord Reversed: ";
//
//Initializes for loop with the limit of the string length
for(int count = charnumber - 1; count >= 0; count--)
cout << a[count]; //Outputs each character in reverse
}