|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
47 strcpy(thePath, path);
48 if(handle = _findfirst(strcat(thepath,"/*.c"),&fa)) != -1L)
C语言入门S1E2的课后作业,
47 9 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp [Error] 'thePath' was not declared in this scope
48 32 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp [Error] 'thepath' was not declared in this scope
48 54 C:\Users\omega\Desktop\FishC\S1E2\未命名4.cpp [Error] expected primary-expression before '!=' token
这哪错了啊???
- #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;
- }
复制代码
|
|