// G. Hagopian==PPP11 exercise 12

/*
12. Reverse the order of characters in a text file. For example, 
asdfghjkl becomes lkjhgfdsa. Warning: There is no really good, 
portable, and efficient way of reading a file backward.
*/

#include <iostream>
#include <fstream>
using namespace std;

int main() {
	ifstream ifs("dadoes.txt");
	ofstream ofs("peehs.txt");
	char ch;
	int length{};
	int i{};
	while (ifs.get(ch) && ch != EOF) {
		++i;
		length = ifs.tellg();
		//cout << length << " ";
		//if (i % 2000 == 0) cin.get();
		cout << ch;
	}
	cout << "\nlength == " << length << endl;
	cin.get();
	cout << "\nlength == " << length << endl;
	//ifs.seekg(0, ifs.beg);
	ifs.clear();
	for (int i = length - 2; i >= 0; --i) {
		ifs.seekg(i);
		ifs.get(ch);
		ofs << ch;
	}
}