// Chapter 2, p 62
#include
#include
const int MAX_LENGTH = 30;
typedef char stringType[MAX_LENGTH+1];
void WriteBackward(stringType S, int Size)
// ---------------------------------------------------
// Writes a character string backward.
// Precondition: The string S contains Size
// characters, where Size >= 0.
// Postcondition: S is written backward, but remains
// unchanged.
// ---------------------------------------------------
{
if (Size > 0)
{ // write the last character
cout << S[Size-1];
// write the rest of the string backward
WriteBackward(S, Size - 1); // Point A
} // end if
// Size == 0 is the base case - do nothing
} // end WriteBackward
// ******SAMPLE MAIN PROGRAM******
main()
{ enum boolean {FALSE, TRUE};
stringType Str;
int Size;
boolean Done;
char Response;
do
{ cout << "Enter string to be written backwards: ";
cin >> Str;
Size = strlen(Str);
cout << "Output from WriteBackward:";
WriteBackward(Str, Size);
cout << "\nContinue? ";
cin >> Response;
} while ((Response != 'n') && (Response != 'N'));
return 0;
} // end program
               (
geocities.com/siliconvalley/program/2864/ds)                   (
geocities.com/siliconvalley/program/2864)                   (
geocities.com/siliconvalley/program)                   (
geocities.com/siliconvalley)