紧急求助!

citytiti 2004-08-26 02:09:36
各位前辈们帮帮我啊,我实在做不出来了,请大家指教一下!先谢谢了!

用VC做一个程序

要求:对C源程序文件进行行数统计的程序,要求输出一个指定目录下的所有.C及.H文件的大小,总行数,代码行数及注释行数.

求大家给我个做法好吗?最好有N-S图,要是有答案就更好了。

求求大家了!
...全文
129 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
citytiti 2004-08-29
  • 打赏
  • 举报
回复
怎么编译时通不过呢?
lixiaosan 2004-08-26
  • 打赏
  • 举报
回复
//test6dlg.h
public:
void FindMyFile(CString path);
void GetFileInfo(CString strpath);
CStringArray strArrFilename;
CStringArray strArrFileLen;
CStringArray strArrLine;
CStringArray strArrCodeLine;
CStringArray strArrNoteLine;
CStringArray strArrSpaceLine;


//test6dlg.cpp
void CTest6Dlg::OnButton5()
{
FindMyFile("D:\\1\\");
CString str="";
for(int i=0; i<strArrFilename.GetSize(); i++)
{
str += "文件名=";
str += strArrFilename[i] + " 文件大小=";
str += strArrFileLen[i] + " 文件行数=";
str += strArrLine[i] + " 代码行数=";
str += strArrCodeLine[i] + " 空白行数=";
str += strArrSpaceLine[i] + " 注释行数=";
str += strArrNoteLine[i] + "\r\n";
}
AfxMessageBox(str);
}

void CTest6Dlg::FindMyFile(CString path)
{
BOOL bFind, bFindSuffix;
CFileFind tempFind, tempFind1;
_chdir(path);
bFind = tempFind.FindFile("*.*");

while(bFind)
{
bFind = tempFind.FindNextFile();
if (tempFind.IsDirectory())
{
if (!tempFind.IsDots() )
{
CString temppath;
temppath = tempFind.GetFilePath();
FindMyFile(temppath);
}
}
}

_chdir(path);
bFindSuffix = tempFind1.FindFile("*.cpp");

while(bFindSuffix)
{
CString strTemp, strpath;
bFindSuffix = tempFind1.FindNextFile();
strTemp = tempFind1.GetFileName();
strpath = tempFind1.GetFilePath();
strTemp.MakeLower();
if( strTemp.Mid(strTemp.ReverseFind('.')+1) == "cpp")
GetFileInfo(strpath);
}
tempFind.Close();
tempFind1.Close();
}

void CTest6Dlg::GetFileInfo(CString strpath)
{
CString strTemp;

strArrFilename.Add(strpath);

CStdioFile file;
if( !file.Open(strpath, CFile::modeRead))
{
AfxMessageBox("can not open file!");
return;
}
DWORD dwFileLen = file.GetLength();
strTemp.Format("%ld", dwFileLen);
strArrFileLen.Add(strTemp);//文件长度

int nCodeLine = 0;//代码行
int nNoteLine = 0;//注释行
int nSpaceLine = 0;//空行
int nLine = 0;//总行
BOOL bNoteS = FALSE;// /*开始标志
BOOL bNoteE = FALSE;// */结束标志
while(file.ReadString(strTemp))
{
nLine++;

strTemp.TrimLeft();
strTemp.TrimRight();

if(!bNoteS)
bNoteS = (strTemp.Find("/*") == 0 )?TRUE:FALSE;
bNoteE = (strTemp.Find("*/", strTemp.GetLength()-2) != -1)?TRUE:FALSE;
if(bNoteS) //找到 /*
{
nNoteLine++;
if(bNoteE)//
{
bNoteS = bNoteE = FALSE;
}
continue;
}

if(strTemp.IsEmpty())
{
nSpaceLine++;
continue;
}
if(strTemp.Find("//") == 0)
{
nNoteLine++;
continue;
}

nCodeLine++;
}

file.Close();

strTemp.Format("%ld", nLine);
strArrLine.Add(strTemp);
strTemp.Format("%ld", nCodeLine);
strArrCodeLine.Add(strTemp);
strTemp.Format("%ld", nNoteLine);
strArrNoteLine.Add(strTemp);
strTemp.Format("%ld", nSpaceLine);
strArrSpaceLine.Add(strTemp);

}
shhbl 2004-08-26
  • 打赏
  • 举报
回复
VCHelp
##################################################################################
1.源码统计器1.0版
最新更新下载:http://xiaogi.diy.163.com

软件介绍:
  在工作中,我们经常碰到客户要求我们告之所写程序的行数,包括代码行、注释行和空白行等。这一软件就是为这一目的编写的。最先是用于对我自己写的C/C++,VC++程序进行行数统计。它可以准确快速地统计出源代码中的各种行数。后来经过不断改进,增加了对VB, Java, ASP,JSP和SQL等程序的源代码的统计,使得软件的应用范围更加广泛。网络上也有不少类似统计行数的软件,但到目前为止,我发现“源码统计器1.0版”统计速度是最快的,而且相比较发现更加准确,考虑到了源代码中可能出现的许多特殊情况。

作者:魏镇江
文件名称:counting
lanstar200 2004-08-26
  • 打赏
  • 举报
回复
網上有源瑪下的,好像www.vchelp.net就有
名牌大灰狼 2004-08-26
  • 打赏
  • 举报
回复
@_@~!

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧