#include <cctype>
#include <iostream>
#include <fstream>

#include"drzewo.h"

using namespace std;

#define MAX 300

string czytaj_slowo(istream &);

int main(int argc, char** argv)
{
	struct drzewo *d=NULL;
	string filename;
    ifstream myFile;
   
   if (argc < 2) 
   {
      cout << "Nazwa pliku: ";
      cin >> filename;
   }
   else filename = argv[1];
 
	myFile.open(filename.c_str());
	
   string  slowo;
	if (myFile.is_open()) 
	{
		while (!myFile.eof()) 
		{
			slowo = czytaj_slowo(myFile);
			if (slowo.length() > 0) d=dodaj(d,slowo);
		 }
	    myFile.close();
	}
   else cout << "Blad - nie udalo sie otworzyc pliku : " << filename << endl;

	wyswietl(d);

	zwolnij(d);
	d=NULL;

	return 0;
}


string czytaj_slowo(istream &i)
{
	char c;
	string slowo;

	while(i.get(c) && isalpha(c))
    {
            slowo = slowo + (char)tolower(c);
    }

	return slowo;
}
