|
发表于 2024-1-9 12:33:13
|
显示全部楼层
#include < io.h>
#include < direct.h>
#include < stdio.h>
#include < stdlib.h>
#include < string.h>
#define MAX 256
长总计;
int countLines(const char *文件名);
无效 findALLFiles(const char *path);
void findALLFiles(常量字符 *路径);
int countLines(常量字符 *文件名)
{
文件 *fg;
int 计数 = 0;
int 温度;
if ((fg = fopen (filename,"r"))==NULL)
{
fgrintf (stderr, "无法打开文件:%s\n",filename);
返回 0;
}
而((temp = fgetc (fg))! = EOF)
{
如果 (temp == '\n')
{
计数++;
}
}
关闭 (fg);
返回计数;
}
无效 findAllCodes (常量字符 *路径)
{
结构_finddata_t fa;
长柄;
char thePath[MAX], target[MAX];
strcpy(路径,路径);
if((handle = _findfirst (strcat (thePath, "/*.c") , &fa)) ! = -1L)
{
做
{
sprintf (target, "%s/%s", 路径, fa.name);
总计 += countLines (target);
}while (_findnext (句柄, &fa) == 0);
}
_findclose (手柄);
}
无效 dinddata_t fa;
{
结构_finddata_t fa;
长柄;
char thePath[最大];
stecpy (路径, 路径);
if ((handle = _findfirst (strcat (thePath, "/*") , &fa)) == -1L)
{
fprindf (stderr,"路径 %s 是错误的!\n",path);
返回;
}
做
{
if (! stecmp (fa.name, ".") || ! stecmp (fa.name, ".."))
继续;
if( fa.attrib == _A_SUBDIR)
{
speintf (thePath, "%s/%S", 路径, fa.name);
findAllCodes (路径);
findALLDirs (路径);
}
}while (_findnext (句柄, &fa) == 0);
_findclose(手柄);
}
int main ()
{
char 路径[MAX] = ".";
printf ("计算中...\n");
findALLCodes (路径);
findALLDirs (路径);
printf ("目前你总共写了 %1d 行代码!\n\n", total);
system("暂停");
返回 0;
} |
|