鱼C论坛

 找回密码
 立即注册
查看: 2750|回复: 17

[已解决]Dev-C++ 编译报错 找了好一会了 请教下

[复制链接]
发表于 2017-2-24 22:56:07 | 显示全部楼层 |阅读模式

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

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

x

  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];
  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. }


复制代码
最佳答案
2017-2-25 23:14:06
屁哥 发表于 2017-2-25 22:06
你好请教一下 编译正常不让运行 是我编译错了么   其他的可以运行

  1. #include <stdio.h>

  2. #define NL "\n"

  3. int main()
  4. {
  5.         printf("Line1 %s ", NL);
  6.         printf("Line2 %s ", NL);

  7.         return 0;
  8. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-2-24 22:59:18 | 显示全部楼层
之前安装这个 还以为全是 汉语的能简单呢 结果 这报错 报的  用哪个 敲半小时就搞定了 这个一个多小时了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-2-24 23:01:12 | 显示全部楼层
无标题.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2017-2-25 08:58:35 | 显示全部楼层
看楼上大小写错了啊。
你肯定是刚学吧,这个是小甲鱼让你练习写代码的,不懂没关系。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-25 09:40:26 | 显示全部楼层
0mrli0 发表于 2017-2-25 08:58
看楼上大小写错了啊。
你肯定是刚学吧,这个是小甲鱼让你练习写代码的,不懂没关系。

额  哦  换小写试试  
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-25 09:53:44 | 显示全部楼层
[code]
#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)
{
2--25.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-25 09:58:29 | 显示全部楼层

你好 这个是什么编译器  好像很神奇的样子
改了 还是有三个错误 这个没找出来。。。。。。。。。[code]
#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)
{
2--25.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-25 10:10:30 | 显示全部楼层

最后三个错误 复制了一下 好像缩进不对 那玩意能不能导致错误啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-2-25 10:21:29 | 显示全部楼层
本帖最后由 0mrli0 于 2017-2-25 10:25 编辑

英语单词查一下,这三个错误跟你刚才的大小写问题错误类型是一样的,变量未定义就引用了。两种情况一种是你就没定义这个变量,另一种就像上边你的大小写问题导致定义的变量和引用的变量不一致。

不过说实话,你现在连错误是什么都不知道就找错误,纠结于此没有什么意义。接着往下学吧。ps版主用的是visual studio,很大的东西。新手用dev、codeblocks这样的就行了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2017-2-25 12:23:02 | 显示全部楼层
屁哥 发表于 2017-2-25 10:10
最后三个错误 复制了一下 好像缩进不对 那玩意能不能导致错误啊

把你修改后的代码完整贴出来
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2017-2-25 21:37:45 | 显示全部楼层
人造人 发表于 2017-2-25 12:23
把你修改后的代码完整贴出来

谢谢 问题 找到了 是前行 有代码 抄错了 把整个一行对一遍就找到了  
还有个后加的分号是中文的  
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-25 22:06:25 | 显示全部楼层
人造人 发表于 2017-2-25 12:23
把你修改后的代码完整贴出来

你好请教一下 编译正常不让运行 是我编译错了么   其他的可以运行

  1. #include <stdio.h>

  2. #define NL '\n'

  3. int main()
  4. {
  5.                 printf("Line1 %s ", NL);
  6.                 printf("Line2 %s ", NL);
  7.                
  8.                 return 0;
  9. }


  10. #include <stdio.h>

  11. #define PI 3.14159
  12. #define S(r) PI * 5 * 5
  13. #define C(r) 2 * PI * r

  14. int main()
  15. {
  16.                 int r = 5;
  17.                
  18.                 printf("半径为5的圆,面积是 %s, 周长是 %s", S(r), C(r));
  19.                
  20.                 return 0;
  21. }
复制代码
QQ图片20170225220121.png
QQ图片20170225220117.png
QQ图片20170225220108.png
QQ图片20170225220102.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-2-25 23:12:50 | 显示全部楼层
屁哥 发表于 2017-2-25 22:06
你好请教一下 编译正常不让运行 是我编译错了么   其他的可以运行
  1. #include <stdio.h>

  2. #define PI 3.14159
  3. #define S(r) PI * 5 * 5
  4. #define C(r) 2 * PI * r

  5. int main()
  6. {
  7.         int r = 5;

  8.         printf("半径为5的圆,面积是 %.2f, 周长是 %.2f", S(r), C(r));

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

使用道具 举报

发表于 2017-2-25 23:14:06 | 显示全部楼层    本楼为最佳答案   
屁哥 发表于 2017-2-25 22:06
你好请教一下 编译正常不让运行 是我编译错了么   其他的可以运行

  1. #include <stdio.h>

  2. #define NL "\n"

  3. int main()
  4. {
  5.         printf("Line1 %s ", NL);
  6.         printf("Line2 %s ", NL);

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

使用道具 举报

 楼主| 发表于 2017-2-27 09:19:10 | 显示全部楼层

还是我 写错了 。。。。。。。。。一会仔细对对
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-27 16:15:16 | 显示全部楼层

。。。。。。。。。没找到哪里不一样 你这个复制了 就可以正常编译运行 我的 就只能编译不能运行  和你这两个一样的代码  上边的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-2-27 17:33:32 | 显示全部楼层
屁哥 发表于 2017-2-27 16:15
。。。。。。。。。没找到哪里不一样 你这个复制了 就可以正常编译运行 我的 就只能编译不能运行  和你这 ...

你还有好长的路要走啊^_^

  1. #if(1)

  2. #include <stdio.h>

  3. //#define NL '\n'
  4. #define NL "\n"

  5. int main()
  6. {
  7.         printf("Line1 %s ", NL);
  8.         printf("Line2 %s ", NL);

  9.         return 0;
  10. }

  11. #else

  12. #include <stdio.h>

  13. #define PI 3.14159
  14. #define S(r) PI * 5 * 5
  15. #define C(r) 2 * PI * r

  16. int main()
  17. {
  18.         int r = 5;

  19.         //printf("半径为5的圆,面积是 %s, 周长是 %s", S(r), C(r));
  20.         printf("半径为5的圆,面积是 %.2f, 周长是 %.2f", S(r), C(r));

  21.         return 0;
  22. }

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

使用道具 举报

 楼主| 发表于 2017-2-27 17:35:34 | 显示全部楼层
人造人 发表于 2017-2-27 17:33
你还有好长的路要走啊^_^

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-1 17:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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