///////////////////////////////////////////////////////// // // arrays.cpp // Started by Jeff Ondich on 10/7/99 // Last modified 10/11/99 // // This program reads words from standard input (cin) // into an array of strings, and then prints the // words out in reverse order. // // This program has a significant problem. If there // are more than 100 words in the input, the array // of strings will overflow, causing unpredictable // behavior. How could you modify the loop to prevent // this problem? // ///////////////////////////////////////////////////////// #include #include const maxWordCount = 100; int main( void ) { // Read words into the array until string theWords[maxWordCount]; int nWords = 0; while( cin >> theWords[nWords] ) { nWords++; } // Print the words out in reverse order. cout << "There are " << nWords << " words in the input." << endl; cout << "Here they are in reverse order." << endl; for( int i=nWords-1; i >= 0; i-- ) cout << theWords[i] << endl; return( 0 ); }