鱼C论坛

 找回密码
 立即注册
查看: 1358|回复: 5

[已解决]刚才是学C的课后作业

[复制链接]
发表于 2020-8-12 23:13:25 | 显示全部楼层 |阅读模式

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

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

x
82        23        C:\Users\Lenovo\Desktop\未命名1.cpp        [Error] 'findALLDirs' was not declared in this scope        这是为什么 我按上面打下来的然后改了好多次最后复制82行的也没用
最佳答案
2020-8-13 06:58:38
可能是你抄错了,直接复制下面的代码看看行不行?


  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 findAllCodes(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-8-12 23:14:50 | 显示全部楼层
发完整代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-12 23:15:28 | 显示全部楼层
本帖最后由 baige 于 2020-8-12 23:37 编辑

这种情况就是你其他地方抄错了,声明,定义都有可能函数名写错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-13 06:58:38 | 显示全部楼层    本楼为最佳答案   
可能是你抄错了,直接复制下面的代码看看行不行?


  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 findAllCodes(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-8-13 08:00:26 | 显示全部楼层
后缀名储存成.c,再不行就复制,你是不是复制linux的了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-26 01:47:32 | 显示全部楼层
没有结帖,正好拿来练习练习

  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
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-20 13:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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