#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 256 // MAX不是max
long total;
int countLines(const char *filename);
void findAllCodes(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 the file: %s\n",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;
long handle;
char thePath[MAX], target[MAX];//抄错了
strcpy(thePath, path);
if(handle = _findfirst(strcat(thePath,"/*.c"),&fa) != -1L)// thePath不是thepath
{
do {
sprintf(target, "%s/%s", path, fa.name);//这里抄错了
total +=countLines(target);
} while (_findnext(handle, &fa) == 0);
}
_findclose(handle);
}
void findAllDirs(const char *path)// findAllDirs不是finndcAllDirs
{
struct _finddata_t fa;
long handle;
char thePath[MAX];
strcpy(thePath,path);// 少了path thePath不是thepath
if((handle = _findfirst(strcat(thePath, "/*"),&fa)) == -1L) // thePath不是thepath
{
fprintf(stderr,"The path %s is wrong!\n",path);
return;
}
do
{
if(!strcmp(fa.name,".")|| !strcmp(fa.name, ".."))//这里抄错了
continue;// continue 不是countinue
if( fa.attrib == _A_SUBDIR)
{
sprintf(thePath,"%s/%s",path,fa.name);// thePath
findAllCodes(thePath);// 同上
findAllDirs(thePath);// 同上
}
} while (_findnext(handle,&fa) == 0);
_findclose(handle);
}
int main()
{
char path[MAX] = ".";
printf("计算中...\n");
findAllCodes(path);
findAllDirs(path);// findAllDirs不是findALLDirs
printf("目前你总共写了%1d行代码!\n\n,total");
system("pause");
return 0;
}
|