鱼C论坛

 找回密码
 立即注册
查看: 1249|回复: 2

[已解决]萌新求助球球各位大佬帮忙看看呗

[复制链接]
发表于 2020-9-24 00:10:54 | 显示全部楼层 |阅读模式

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

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

x
《带你学C带你飞》第一科作业,请问下各位大佬这是怎么回事呀,报错如下C:\Users\朱的猪\Desktop\c\zuoye.c        In function 'countLines':
19        2        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
22        6        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] 'fp' undeclared (first use in this function)
22        6        C:\Users\朱的猪\Desktop\c\zuoye.c        [Note] each undeclared identifier is reported only once for each function it appears in
C:\Users\朱的猪\Desktop\c\zuoye.c        In function 'findAllCodes':
43        20        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'fa'
43        20        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] 'fa' undeclared (first use in this function)
47        9        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] 'thePathk' undeclared (first use in this function)
52        32        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] expected ')' before 'fa'
C:\Users\朱的猪\Desktop\c\zuoye.c        In function 'findALLDirs':
62        20        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'fa'
62        20        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] 'fa' undeclared (first use in this function)
69        43        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] request for member 'path' in something not a structure or union
70        2        C:\Users\朱的猪\Desktop\c\zuoye.c        [Error] expected ';' before '}' token


  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. while ((temp=fgetc(fp))!=EOF)
  23. {
  24.         if(temp=='\n')
  25.         {
  26.                 count++;
  27.         }
  28. }

  29.     fclose(fp);
  30.    
  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.        
  39.         strcpy(thePathk,path);
  40.         if((handle=findfirst(strcat(thePath,"/*.c"),&fa))!=-1L)
  41.         {
  42.                 do
  43.                 {
  44.                         sprintf(target,"%s/%s",path fa.name);
  45.                         total+=countLines(target);
  46.                 }while(findnext(handle,&fa)==0);
  47.         }
  48.        
  49.         findclose(handle);
  50. }

  51. void findALLDirs(const char *path)
  52. {
  53.         struct finddata t fa;
  54.         long handle;
  55.         char thePath[MAX];
  56.        
  57.         strcpy(thePath,path);
  58.         if((handle=findfirst(strcat(thePath,"/*"),&fa))==-1L)
  59.         {
  60.                 fprintf(stderr,"The path %s is wrong!\n".path)
  61.         }

  62.     do
  63.     {
  64.             if(!strcmp(fa.name,".."))
  65.                      continue;
  66.                     
  67.             if(fa.attrib==_A_SUBDIR)
  68.             {
  69.                     sprintf(thePath,"%s/%s",path,fa.name);
  70.                     findAllCodes(thePath);
  71.                     findALLDirs(thePath);
  72.                 }
  73.         }while(findnext(handle,&fa)==0);
  74.        
  75.         findclose(handle);
  76. }

  77. int main()
  78. {
  79.         char path[MAX]=".";
  80.        
  81.         printf("计算中...\n");
  82.         findAllCodes(path);
  83.        
  84.         printf("目前你总共写了 %ld 行代码!\n\n",total);
  85.         system("pause");
  86.        
  87.         return 0;
  88. }
复制代码
最佳答案
2020-9-24 06:54:18
18行少了个分号,导致其他行也报错了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-9-24 06:54:18 From FishC Mobile | 显示全部楼层    本楼为最佳答案   
18行少了个分号,导致其他行也报错了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-24 08:39:17 | 显示全部楼层
本帖最后由 China陈永华 于 2020-9-24 08:49 编辑



谢谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-4 14:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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