#include <iostream>
#include <fstream>
#include <direct.h>
#include <io.h>
#include <string>
#include "my_dll1.hpp"
using namespace std;
int countLine(char *filename);
void countBrowseLine(char *pathName, char *filetype);
int main(int argc, char *argv[])
{
if (*(argv+1)==NULL || *(argv+2)==NULL )
{
return 0;
}
char str[50];
strcpy(str,*(argv+1));
char type[20];
strcpy(type,*(argv+2));
countBrowseLine(str,type);
system("pause");
return 0;
}
void countBrowseLine(char *pathName,char *filetype)
{
_chdir(pathName);
_finddata_t fdata;
int nTotal = 0;
int n = 0;
long label = _findfirst(filetype,&fdata);
do
{
cout << "the lines of the " << fdata.name << " is ";
n = countLine(fdata.name);
nTotal += n;
cout << n << endl;
} while (_findnext(label,&fdata) == 0);
cout << "all the lines of the browse about "<< filetype<<" is " << nTotal << endl;
}
int countLine(char *filename)
{
int nCount = 0;
fstream fin(filename);
char c[300];
if (!fin)
{
cout << "读取文件错误"<< endl;
return 0;
}
while (!fin.eof())
{
fin.getline(c,300);
++nCount;
}
fin.close();
return nCount;
}