#include <iostream>
using std::cout;
#include <fstream>
using std::ifstream;
#include <string>
using std::string;
//precondition: a string and a reference to an input file stream
//postcondition: true only if string is in the file after the point referenced by the ifstream
bool isWord(const string& w, ifstream& fs) {
	string word;
	while (fs >> word) {
		if (word == w) return true;
	}
	return false;
}

bool isShrinkingWord(string& w, ifstream& fs) {
	cout << "Check if " << w.substr(1,w.size()-1) << " is a word.\n";
	cout << "isWord(" << w.substr(1) << ", fs)=";
	fs.clear();
	fs.seekg(0);
	cout << isWord(w.substr(1), fs) << '\n';
	fs.clear();
	fs.seekg(0);
	if (isWord(w.substr(1),fs)) {
		cout << w.substr(1) << " is a word.\n";
		fs.clear();
		fs.seekg(0);
		return true;
	}
	else if (isWord(w.substr(0, w.size() - 2),fs)) {
		fs.clear();
		fs.seekg(0);
		cout << w.substr(0, w.size() - 2) << " is a word." << '\n';
		return true;
	}
	else {
		fs.clear();
		fs.seekg(0);
		return false;
	}
}

int main() {
	ifstream fs("ospd.txt");
	if (!fs) cout << "failed.";
	string werd;
	cout << "Enter a word to see if it's an English word:\n";
	while (std::cin >> werd) {
		fs.clear();
		fs.seekg(0);
		cout << werd << " is";
		if (!isWord(werd, fs))
			cout << " not";
		cout << " an English word, and ";
		if (isShrinkingWord(werd, fs));
			//cout << " is also a word.";
		cout << "Enter a word to see if it's an English word:\n";
	}
}