您的位置:首页 > 编程语言 > C语言/C++

统计一个项目的代码行数,只统计cpp文件

2008-12-30 18:33 846 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: