鱼C论坛

 找回密码
 立即注册
查看: 1195|回复: 11

[已解决]findAllCodessa 未在范围声明中

[复制链接]
发表于 2020-9-15 09:07:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 让学习使我快乐 于 2020-9-15 09:10 编辑

告诉我findAllCodessa  没有在范围声明中 (百度翻译的)  这两行已经重复打了好几遍了 就算是复制甲鱼的粘贴上去也不行  是别的地方出错了吗

一
最佳答案
2020-9-16 14:43:09
本帖最后由 LuLD 于 2020-9-16 14:51 编辑


首先 你的代码缩进有问题,肉眼看你的缩进太多了,应该是四个空格或是一个Tab(字母Q旁边的那个)

其次就是 你报错的那个函数,最顶上声明的是 void findA11Codes(const char *path);  All中的 L 是小写的 ,代码 13 行
而 下面的定义 又是void findALLCodes(const char *path),All中的字母L又变成了大写,代码41 行

C语言是严格要求字母的大小写的


还有就是你说复制小甲鱼的代码 也不能运行是因为,文件的后缀名不对,这个上面已经讲过了,应该是 .c
Snipaste_2020-09-16_14-42-15.bmp




  1. int countLines(const char *filename)
  2. {
  3.         FILE *fp;
  4.         int count = 0;
  5.         int temp;
  6.         
  7.         if ((fp = fopen(filename, "r")) == NULL)
  8.         {
  9.                 fprintf(stderr, "Can not open the file:%s\n", filename);
  10.                 return 0;
  11.         }
  12.         
  13.         while ((temp = fgetc(fp)) != EOF)
  14.         {
  15.                 if (temp == '\n')
  16.                 {
  17.                         count++;
  18.                 }
  19.         }
  20.         
  21.         fclose(fp);
  22.         
  23.         return count;
  24. }
  25. //上面是改好缩进的
  26. //Dec++ 的我不清楚这个缩进是否有严格要求
  27. //以下是复制你的代码,看缩进
  28. int countLines(const char *filename)
  29. {
  30.             FILE *fp;
  31.             int count = 0;
  32.             int temp;
  33.             
  34.             if ((fp = fopen(filename, "r")) == NULL)
  35.             {
  36.                         fprintf(stderr,"Can not open the file: %s\n",filename);
  37.                         return 0;
  38.                 }
  39.                
  40.                 while ((temp = fgetc(fp)) != EOF)
  41.                 {
  42.                             if (temp =='\n')
  43.                             {
  44.                                        count++;
  45.                                 }
  46.                 }
  47.                
  48.                 fclose(fp);
  49.                
  50.                 return count;
  51. }

复制代码

二

三

四

不知道为啥不能运行

不知道为啥不能运行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-9-15 09:21:22 | 显示全部楼层
应该是 小甲鱼的 那个 计算你写了多少行代码的吧?
那应该是 C
C的后缀名 应该是 .c
.cpp 是C++ 的

还有就是 把你的代码贴出来,图片看着太纠结了
Snipaste_2020-09-14_10-27-31.bmp
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-15 09:58:35 | 显示全部楼层
你将程序名 “未命名2.cpp” 重命名为:未命名2.c 再试试
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-16 11:30:11 | 显示全部楼层
LuLD 发表于 2020-9-15 09:21
应该是 小甲鱼的 那个 计算你写了多少行代码的吧?
那应该是 C
C的后缀名 应该是 .c

  1. #include <io.h>
  2. #include <direct.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>

  6. #define MAX          256

  7. long total;

  8. int countLines(const char *filename);
  9. void findA11Codes(const char *path);
  10. void findALLFiles(const char *path);

  11. int countLines(const char *filename)
  12. {
  13.             FILE *fp;
  14.             int count = 0;
  15.             int temp;
  16.             
  17.             if ((fp = fopen(filename, "r")) == NULL)
  18.             {
  19.                         fprintf(stderr,"Can not open the file: %s\n",filename);
  20.                         return 0;
  21.                 }
  22.                
  23.                 while ((temp = fgetc(fp)) != EOF)
  24.                 {
  25.                             if (temp =='\n')
  26.                             {
  27.                                        count++;
  28.                                 }
  29.                 }
  30.                
  31.                 fclose(fp);
  32.                
  33.                 return count;
  34. }

  35. void findALLCodes(const char *path)
  36. {
  37.             struct _finddata_t fa;
  38.             long handle;
  39.             char thePath[MAX], target[MAX];
  40.             
  41.             strcpy(thePath,path);
  42.             if((handle = _findfirst(strcat(thePath,"/*.c"),&fa)) != -1L)
  43.             {
  44.                         do
  45.                         {
  46.                                     sprintf(target,"%s%s",path,fa.name);
  47.                                     total += countLines(target);
  48.                                 }while (_findnext(handle,&fa) == 0);
  49.                 }
  50.                
  51.                 _findclose(handle);
  52. }

  53. void findALLDirs(const char *path)
  54. {
  55.              struct _finddata_t fa;
  56.              long handle;
  57.              char thePath[MAX];
  58.                   
  59.                  strcpy(thePath,path);
  60.                  if((handle = _findfirst(strcat(thePath,"/*"), &fa)) == -1L)
  61.                  {
  62.                               fprintf(stderr,"The path %s is wrong!\n",path);
  63.                               return;
  64.                  }
  65.                  
  66.                  do
  67.                  {
  68.                               if (!strcmp(fa.name,".") || !strcmp(fa.name,".."))
  69.                                      continue;
  70.                                     
  71.                              if( fa.attrib == _A_SUBDIR)
  72.                                  {
  73.                                              sprintf(thePath,"%s%s",path,fa.name);
  74.                         findAllCodes(thePath);
  75.                                              findALLDirs(thePath);
  76.                                   }
  77.                  }while (_findnext(handle,&fa) == 0);
  78.                  
  79.                  _findclose(handle);
  80. }

  81. int main()
  82. {
  83.              char path[MAX] =".";
  84.              
  85.              printf("计算中...\n");
  86.              
  87.              findAllCodes(path);
  88.              findALLDirs(path);
  89.              
  90.              printf("目前你总写了 %ld 行代码! \n\n", total);
  91.              system("pause");
  92.              
  93.              return 0;
  94. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-16 12:10:23 | 显示全部楼层

代码没有问题,问题在你的文件名是不是 .c
S1E2.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-16 14:43:09 | 显示全部楼层    本楼为最佳答案   
本帖最后由 LuLD 于 2020-9-16 14:51 编辑


首先 你的代码缩进有问题,肉眼看你的缩进太多了,应该是四个空格或是一个Tab(字母Q旁边的那个)

其次就是 你报错的那个函数,最顶上声明的是 void findA11Codes(const char *path);  All中的 L 是小写的 ,代码 13 行
而 下面的定义 又是void findALLCodes(const char *path),All中的字母L又变成了大写,代码41 行

C语言是严格要求字母的大小写的


还有就是你说复制小甲鱼的代码 也不能运行是因为,文件的后缀名不对,这个上面已经讲过了,应该是 .c
Snipaste_2020-09-16_14-42-15.bmp




  1. int countLines(const char *filename)
  2. {
  3.         FILE *fp;
  4.         int count = 0;
  5.         int temp;
  6.         
  7.         if ((fp = fopen(filename, "r")) == NULL)
  8.         {
  9.                 fprintf(stderr, "Can not open the file:%s\n", filename);
  10.                 return 0;
  11.         }
  12.         
  13.         while ((temp = fgetc(fp)) != EOF)
  14.         {
  15.                 if (temp == '\n')
  16.                 {
  17.                         count++;
  18.                 }
  19.         }
  20.         
  21.         fclose(fp);
  22.         
  23.         return count;
  24. }
  25. //上面是改好缩进的
  26. //Dec++ 的我不清楚这个缩进是否有严格要求
  27. //以下是复制你的代码,看缩进
  28. int countLines(const char *filename)
  29. {
  30.             FILE *fp;
  31.             int count = 0;
  32.             int temp;
  33.             
  34.             if ((fp = fopen(filename, "r")) == NULL)
  35.             {
  36.                         fprintf(stderr,"Can not open the file: %s\n",filename);
  37.                         return 0;
  38.                 }
  39.                
  40.                 while ((temp = fgetc(fp)) != EOF)
  41.                 {
  42.                             if (temp =='\n')
  43.                             {
  44.                                        count++;
  45.                                 }
  46.                 }
  47.                
  48.                 fclose(fp);
  49.                
  50.                 return count;
  51. }

复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-16 15:08:29 | 显示全部楼层
本帖最后由 LuLD 于 2020-9-16 15:10 编辑


刚刚我又试了一下,缩进不会报错,但是最后运行的结果  写了 0 行代码


希望你能继续保持 心态,努力的学习下去
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-16 15:48:52 | 显示全部楼层
  1. // 该程序必须在 C 编译器下运行,C++ 编译器下不能运行!

  2. // 有些编译器对缩进也有严格的要求,所以,请不要改变每一行前的空格!

  3. #include <io.h>
  4. #include <direct.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>

  8. #define MAX        256

  9. long total;

  10. int countLines(const char *filename);
  11. void findAllCodes(const char *path);
  12. void findALLFiles(const char *path);

  13. int countLines(const char *filename)
  14. {
  15.     FILE *fp;
  16.     int count = 0;
  17.     int temp;

  18.     if ((fp = fopen(filename, "r")) == NULL)
  19.         {
  20.         fprintf(stderr, "Can not open the file: %s\n",filename);
  21.         return 0;
  22.         }

  23.     while ((temp = fgetc(fp))!= EOF)
  24.         {
  25.         if(temp == '\n')
  26.                 {
  27.             count++;
  28.                 }
  29.         }

  30.     fclose(fp);

  31.     return count;
  32. }

  33. void findAllCodes(const char *path)
  34. {
  35.     struct _finddata_t fa;
  36.     long handle;
  37.     char thePath[MAX], target[MAX];

  38.     strcpy(thePath,path);
  39.     if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
  40.         {
  41.         do
  42.                 {
  43.             sprintf(target, "%s/%s", path, fa.name);
  44.             total += countLines(target);
  45.                 }
  46.         while (_findnext(handle, &fa) == 0);
  47.         }

  48.     _findclose(handle);
  49. }

  50. void findALLDirs(const char *path)
  51. {
  52.     struct _finddata_t fa;
  53.     long handle;
  54.     char thePath[MAX];

  55.     strcpy(thePath, path);
  56.     if((handle =  _findfirst(strcat(thePath, "/*"),&fa)) == -1L)
  57.         {
  58.         fprintf(stderr, "The path %s is wrong!\n",path);
  59.         return;
  60.         }

  61.     do
  62.         {
  63.         if(!strcmp(fa.name, ".") || !strcmp(fa.name, ".."))
  64.             continue;

  65.         if( fa.attrib == _A_SUBDIR)
  66.                 {
  67.             sprintf(thePath, "%s/%s", path, fa.name);
  68.             findAllCodes(thePath);
  69.             findALLDirs(thePath);
  70.                 }
  71.         }
  72.     while (_findnext(handle, &fa) == 0);

  73.     _findclose(handle);
  74. }

  75. int main()
  76. {
  77.     char path[MAX] = ".";

  78.     printf("计算中...\n");

  79.     findAllCodes(path);    // C要大写
  80.     findALLDirs(path);

  81.     printf("目前你总共写了 %ld 行代码! \n\n", total);
  82.     system("pause");

  83.     return 0;
  84. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-16 16:58:45 | 显示全部楼层

吓我一跳,我还以为我写错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-17 00:54:53 | 显示全部楼层
LuLD 发表于 2020-9-16 16:58
吓我一跳,我还以为我写错了

我是要完成每天的回帖数,得到积分才能升级,才会有某些非某个级别才能有的权利,比如隐藏帖子中的部分内容,比如拥有自己的签名。。。。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-17 09:47:15 | 显示全部楼层
风过无痕1989 发表于 2020-9-17 00:54
我是要完成每天的回帖数,得到积分才能升级,才会有某些非某个级别才能有的权利,比如隐藏帖子中的部分内 ...

嗯呐,也不知道这哥们儿理解了没有
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-21 09:21:39 | 显示全部楼层
谢谢大家的详细讲解我理解了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 14:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表