/*******************************************************************************
* Aiden Stannard // CS1A // Chapter 10 Homework: Challange 2# // 11/28/2026
* _____________________________________________________________________________
*
* String Reverser
* _____________________________________________________________________________
*
* This program accepts a CString and outputs the contents of the CString in
* reverse order.
* _____________________________________________________________________________
*
* Input: Enter a five letter word___
*
* Output: The enterd five letter word is___ in reverse
*
******************************************************************************/
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
void reverse(char *, int);
int main() {
int size = 6;
char test[size] = "Hello"; // c string
char *ptr = test; // c string pointer
cout << "Enter a five letter word " << endl;
cin >> test; // user enters word
reverse(ptr, size); // The string pointer and c string size is passed to the
// function
return 0;
}
void reverse(char *test, int size){
int x = size - 2;
cout << x << endl;
for (int i = 0; i < (size - 1) and !(x == i); i++)
{
char temp = test[i]; // reversed string by swapping the first element
test[i] = test[x]; // with the last element, incrementing/dec those
test[x] = temp; // elements until they equal one another, ending the loop
x--;
}
cout << "The entered five letter word, is " << test << " in reverse" << endl;
}