|
发表于 2019-5-16 22:02:47
|
显示全部楼层
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#define MAX 256
;
int countlines ( const char * filename ) ;
void ficdAllCodes ( const char * path );
viod findALLFiles ( const char * path );
int countLines ( const char*filename )
{
FILE * fp;
int count = 0;
int temp;
if ( ( fp = fopen ( filename, "r")) == NULL)
{
fprintf ( stderr, "无法打开文件: %s\n",filename);
return 0;
}
while (( temp = fgetc ( fp ) ) ! = EOF )
{
if ( temp == '\n')
{
计数++;
}
}
FCLOSE ( FP );
返回计数;
}
void findALLCodes ( const char * path )
{
strnct finddata t fa;
长柄;
char thePath [MAX], 目标[MAX];
strcpy ( thePath, path);
if ((handle = _findfirst (strcat (thePath,"/ *。c"), &fa)) ! = -1L)
{
做
{
sprintf (target, "%s/%s",path, fa.name);
总计+ = countLines ( 目标 );
} while (_findnext (handle, &fa ) == 0);
}
_findclose (手柄);
}
void findALLDirs ( const char * path )
{
struct _finddata_t fa;
长柄;
char thePath [MAX];
strcpy ( thePath, path );
if (( handle = _findfirst (strcat ( thePath,"/ *" ) ,&fa ) ) == -1L)
{
fprintf( stderr,"路径%s错了!\n",路径);
return;
}
做
{
if(!strcmp(fa.name,"。")||!strcmp ( fa.name,".." ) )
继续;
if( fa.attirb == _A_SUBDIR )
{
sprintf ( thePath,"%s/%s",path,fa.name);
findALLCodes ( thePath );
findALLDirs ( thePath );
}
} while (_findnext ( handle, &fa ) == 0 );
_findclose ( 手柄 );
}
int main()
{
char path[MAX] = "。";
的printf( "计算中…\n");
findALLCodes (路径);
findALLDirs(路径);
printf("目前你总共写了%ld行代码!\n\n",总计);
系统("暂停");
return 0;
} |
|