//Devin Scheu CS1A Chapter 10, P. 588, #2
//
/**************************************************************
*
* DISPLAY C-STRING BACKWARD
* ____________________________________________________________
* This program reverses and displays the contents of a C-string.
* ____________________________________________________________
* INPUT
* inputString : The C-string entered by the user
*
* OUTPUT
* reversedString : The reversed contents of the C-string
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Function to display C-string backward using pointer notation
void displayBackward(const char* str) {
const char* end = str;
while (*end != '\0') {
end++;
}
end--; // Move back to the last character
while (end >= str) {
cout << *end;
end--;
}
cout << endl;
}
int main () {
//Variable Declarations
const int MAX_SIZE = 100; //OUTPUT - Maximum size of the input string
char inputString[MAX_SIZE]; //INPUT - The C-string entered by the user
string reversedString; //OUTPUT - The reversed contents of the C-string
//Prompt for Input and Echo
cout << "Enter a string (max 99 characters): ";
cin.getline(inputString, MAX_SIZE);
cout << inputString << endl;
//Separator and Output Section
cout << "-------------------------------------------------------" << endl;
cout << "OUTPUT:" << endl;
//Display Backward
cout << left << setw(25) << "Reversed String:" << right;
displayBackward(inputString);
} //end of main()