#include <iostream>
#include <fstream>
#include <string.h>
#include <stdlib.h>
using namespace std;
int words(char *line)
{
int words=0;
bool Prechar=false;
bool Curchar=false;
for(unsigned i=0;i<strlen(line);i++)
{
if((line[i]>='A'&&line[i]<='Z')||(line[i]>='a'&&line[i]<='z'))
{
Curchar=true;
}
else
{
Curchar=false;
}
if(!Prechar&&Curchar)
{
words++;
}
Prechar=Curchar;
}
return words;
}
int main()
{
const int N =1024;
char line[N];
int lines=0;
int Totalwords=0;
char filename[40];
ifstream txtfile;
cout<<"txtfile name:"<<endl;
cin>>filename;
txtfile.open(filename);
if(!txtfile)
{
cout<<"txtfile open fial!"<<endl;
exit(1);
}
while(txtfile.getline(line,N))
{
Totalwords+=words(line);
lines++;
}
txtfile.close();
cout<<"Total words is:"<<Totalwords<<endl;
cout<<"Total lines is:"<<lines<<endl;
return 0;
}