// Example 11.1. Program to read a string and print its reverse #include using namespace std; int main() { int stringLength(const char []); // prototype const int MAX_LENGTH = 15; // maximum length of string char word[MAX_LENGTH + 1]; // holds the string int stringSize; // actual string length int i; // index cout << "Please enter a word of up to " << MAX_LENGTH << " letters: "; cin >> word; cout << "The word is " << word << "." << endl; stringSize = stringLength(word); cout << "The reversed word is "; for (i = stringSize - 1; i >= 0; --i) cout << word[i]; cout << "." << endl; return 0; } // // Function to return the string length // Pre: str is a char array containing a string. // Post: The length of string was returned. // int stringLength(const char str[]) { int stringSize = 0; // actual string length while (str[stringSize] != '\0') ++stringSize; return stringSize; }