|
|
发表于 2022-9-18 15:58:48
|
显示全部楼层
#include <>
#include <直>
#include <体育场>
#include <斯特利布>
#include <弦>
#define最大 256
长总计;
int countLines(常量字符 *文件名);
void findAllCodes(const char *path);
void 查找ALLFiles(const char *path);
int countLines(常量字符 *文件名)
{
文件 *fp;
整数计数 = 0;
温度;
如果 ((fp = 源(文件名,“r”)) == 空)
{
fprintf(stderr, “无法打开文件:%s\n”, 文件名);
返回 0;
}
而 ((温度 = fgetc(fp)) != EOF)
{
如果 (温度 == '\n')
{
计数++;
}
}
断续器;
返回计数;
}
void findAllCodes(const char *path)
{
结构_finddata_t法;
长手柄;
字符路径[最大], 目标[最大];
strcpy(路径,路径);
if((handle = _findfirst(strcat(路径, “/*.c”), &fa)) != -1L)
{
做
{
sprintf(目标, “%s/%s”, path, fa.name);
总计 += 计数线(目标);
}而 (_findnext(句柄, &fa) == 0);
}
_findclose(手柄);
}
void findALLDirs(const char *path)
{
结构_finddata_t法;
长手柄;
字符路径[最大];
strcpy(路径,路径);
如果((句柄 = _findfirst(strcat(路径, “/*”), &fa)) == -1L)
{
fprintf(stderr, “路径 %s 是错误的!\n”,path);
返回;
}
做
{
如果 (!斯特坎普(fa.name, “.”) || !斯特坎普(fa.name, “..”)
继续;
如果( 法阿特里布 == _A_SUBDIR)
{
sprintf(路径, “%s/%s”, path, fa.name);
查找所有代码(路径);
查找ALLDirs(路径);
}
}而 (_findnext(句柄, &fa) == 0);
_findclose(手柄);
}
int main()
{
字符路径 [最大] = “.”;
printf(“计算中...\n”);
查找所有代码(路径);
查找ALLDirs(路径);
printf(“目前你总共写了 %ld 行代码!\n\n”, total);
系统(“暂停”);
返回 0;
} |
|