|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Yong__heng 于 2020-3-1 16:32 编辑
刚刚看完视频打完这个《统计当前目录及所有子目录下,C 语言源文件的代码总行数。》发现第97行有问题但不知道错在哪里。求大佬帮我看一下。。。。。。。。。。。。谢谢
- #include <io.h>
- #include <direct.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 256
- 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)
- {
- do
- {
- sprintf(target,"%s/%s",path,fa.name);
- total += countlines(target);
- }while(_findnext(handle,&fa) == 0);
- }
-
- _findclose(handle);
- }
- void findALLDirs(const char *path)
- {
- struct _finddata_t fa;
- long handle;
- char thePath[MAX];
-
- strcpy(thePath,path);
- if((handle = _findfiret(strcat(thePath,"/*"), &fa)) == -1L)
- {
- fprintf(stderr,"The pat %s wrong!\n",path);
- return;
-
- }
-
- do
- {
- if(!strcmp(fa.name,".")|| !strcmp(fa.name,".."))
- continue;
-
- if( fa.attrib == _A_SUBDIR)
- {
- sprintf(thePath, "%s/%s",path, fa.name);
- findAllcodes(thePath);
- findALLDirs(thePath);
-
- }
- }while(_findnext(handle,&fa) == 0);
-
- _findclose(handle);
- }
- int main()
- {
- char ath[MAX] = ".";
-
- print("计算中...\n");
-
- findAllCodes(path); /*这行*/
- findALLDirs(path);
-
- printf("目前你总共写了 %ld 行代码! \n\n",total);
- system("pause");
-
- return 0;
- }
复制代码
还有这个怎么弄成代码格式
我不会弄???????????
谢谢路过的大佬
代码错误至少有5个。。。
我直接发代码了,基本都是拼写错误,还有一个函数忘了声明
- #include <io.h>
- #include <direct.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 256
- long total;
- int countlines(const char *filename);
- void findAllCodes(const char *path);
- void findAllfiles(const char *path);
- void findALLDirs(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)
- {
- do
- {
- sprintf(target,"%s/%s",path,fa.name);
- total += countlines(target);
- }while(_findnext(handle,&fa) == 0);
- }
-
- _findclose(handle);
- }
- void findALLDirs(const char *path)
- {
- struct _finddata_t fa;
- long handle;
- char thePath[MAX];
-
- strcpy(thePath,path);
- if((handle = _findfirst(strcat(thePath,"/*"), &fa)) == -1L)
- {
- fprintf(stderr,"The pat %s wrong!\n",path);
- return;
-
- }
-
- do
- {
- if(!strcmp(fa.name,".")|| !strcmp(fa.name,".."))
- continue;
-
- if( fa.attrib == _A_SUBDIR)
- {
- sprintf(thePath, "%s/%s",path, fa.name);
- findAllCodes(thePath);
- findALLDirs(thePath);
-
- }
- }while(_findnext(handle,&fa) == 0);
-
- _findclose(handle);
- }
- int main()
- {
- char path[MAX] = ".";
-
- printf("计算中...\n");
-
- findAllCodes(path); /*这行*/
- findALLDirs(path);
-
- printf("目前你总共写了 %ld 行代码! \n\n",total);
- system("pause");
-
- return 0;
- }
复制代码
发代码找<>这个符号
|
|