#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include "anaword.h"
#include "prompt.h"
#include "tvector.h"
#include "sortall.h"



void FindAnagrams(tvector<Anaword>& list)
// pre: list contains list.size() elements
// post: all anagrams in list printed, one set of anagrams per line
{
    QuickSort(list,list.size());
}

int main(int argc, char * argv[])
{
    tvector<Anaword> list;
    ifstream input;
    string filename,word;
    // use command line argument if it exists, else prompt user
    
    if (argc > 1)
    {
	filename = argv[1];
    }
    else
    {
	filename = PromptString("enter file name ");	
    }
    
    input.open(filename.c_str());
    if (input.fail())
    {
	cerr << "could not open " << filename << endl;
	exit(1);
    }

    while (input >> word)
    {
	list.push_back(Anaword(word));
    }
    cout << endl << "read " << list.size() << " words" << endl;

    FindAnagrams(list);

    return 0;
}

