|
5啊哈币
- #inciude<io.h>
- #inciude<direct.h>
- #inciude<stdio.h>
- #inciude<stdlib.h>
- #inciude<string.h>
- #define MAX 256
- long total;
- int countLines(const char *filename);
- void finfAllCodes(const char *path);
- void findALLFiles(const char *path);
- int countLines(const char *filename)
- {
- FILE*fp;
- int count=0;
- int temp;
-
- if((fp=fopen(filename,"r"))==NULL)
- {
- fprintf(stderr,"Can not open thr file: %s",filename);
- return 0;
- }
-
- while((temp=fgetc(fp))!=EOF)
- {
- IF(TEMP=='N')
- {
- COUNT++;
- }
- }
-
- fclose(fp);
-
- return count;
- }
- void findAllCodes(const char *path)
- {
- struct_finddata_t fa;
- iong handle;
- char thePath[MAX],target[MAX];
-
- strcpy(thePath,path);
- if((handle=_flndflrst(strcat(thepath,"/*.c"),&fa))!=-1L)
- {
- do
- {
- sprintf(target,"%s/%s",path,fa.name);
- total+= countLines(target);
- }while(_findnext(handle,&fa)==0);
- }
-
- _findclose(handle)
- }
- void findALLDirs(const chat *path)
- {
- struct_finddata_t fa;
- long handle;
- char thepath[MAX];
-
- strcpy(thePath,path);
- if((handle=_findflrst(strcat(thePath,"/*"),&fa))==-1L)
- {
- FPRINTF(STDERR,"tHE Path %s is wrong!",path);
- return;
- }
-
- do
- {
- if(!strcmp(fa.name,".")II!strcmp(fa.name,".."))
- continue;
-
- if(fa.attrib==_A_SUBDIR)
- {
- sprintf(thePath,"%s/&s',path,fa.name);
- findAIICodes(thepath);
- findALLDirs(thePath);
- }
- }while(_fiednext(handle,&fa)==0);
-
- _findclose(handle);
- }
- int main()
- {
- char path[MAX]=".";
-
- printf("计算中...");
-
- findAIICodes(path);
- findALLDirs(path);
-
- printf("目前你总共写了 %id行代码!",total);
- system("pause");
-
- return 0;
复制代码 |
|