//Cecilia Rangel CSC5 Chapter 10, P.588, #2
//
/**************************************************************
*
* Backwards string
* ____________________________________________________________
* This program returns an integer and accepts a
* pointer to a C-string as an arguement. The
* function flips the characters in the
* string and returns that string.
*_____________________________________________________________
* INPUT
* userinput : INPUT a string from the user
*
* OUTPUT
* backwards : OUTPUT the string from the user backwards
*
* ***************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
void DisplayBackwards(char* ptr);
int main()
{
//
//Declare varaibles and pointers
int SIZE = 100; //Initialize size to 100
char userInput[SIZE]; //User input
char* ptr; //Pointer to character type
ptr = userInput; //Assign pointer to array
//
//Prompt user to enter character string
cout << "Enter a character string.\n";
cin.getline(userInput, SIZE);
//
//Call function
DisplayBackwards(ptr);
return 0;
}
//
//Display string backwards
void DisplayBackwards(char* ptr)
{
int count;
int size = 0;
int element = 0;
//
//Find size of string array
for (count = 0; *(ptr + count) != '\0'; count++)
size++;
//
//Display string backwards
for (element = size; element >= 0; element--)
{
cout << *(ptr + element);
}
}