//#include<stdlib.h>
//#include<ctype.h>
#include <cctype>
//#include <stdio.h>
#include <iostream>
#include <fstream>

#include"drzewo.h"

using namespace std;


#define MAX 200

//int czytaj_slowo(FILE *strumien,char *slowo,int max);
string czytaj_slowo(istream &);

int main(int argc, char** argv)
{
	struct drzewo *d=NULL;
	//char slowo[MAX];
	string filename;
	//FILE *plik=stdin;
	cout << "Podaj nazwe pliku : " ;
	cin >> filename;
//	if (argc > 1 && !(plik=fopen(argv[1],"r"))) plik=stdin;

	 ifstream myFile;
	 myFile.open(filename.c_str());
 
	string  slowo;
	if (myFile.is_open()) 
	{
		while (!myFile.eof()) 
		{
		  //  myFile >> slowo;
			slowo = czytaj_slowo(myFile);
			if (slowo.length() > 0) d=dodaj(d,slowo);
		 }

		    myFile.close();
	}else cout << "Blad - nie udalo sie otworzyc pliku : " << filename << endl;

//	while(!feof(plik))
//		if(czytaj_slowo(plik,slowo,MAX)) d=dodaj(d,slowo);



	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;
}