#include #include #include using namespace std; int main() { ifstream fi; fi.open("animals.txt"); if (fi.fail()) { cout << "Can't open animals.txt\n"; exit(1); } const int maxwords = 200; string words[maxwords]; int count = 0; while (true) { string s; fi >> s; if (fi.fail()) break; if (count >= maxwords) { cout << "data file too big for array\n"; exit(3); } words[count] = s; count = count + 1; } cout << "There were " << count << " words in the file.\n"; fi.close(); ofstream fo; fo.open("newanimals.txt"); if (fo.fail()) { cout << "Can't create newanimals.txt\n"; exit(2); } int i = count - 1; while (i >= 0) { fo << words[i] << "\n"; i = i - 1; } fo.close(); }