鱼C论坛

 找回密码
 立即注册
查看: 5236|回复: 28

[已解决]DEV C++ 中运行程序错误后 某行代码被红色条框起来是什么意思

[复制链接]
发表于 2020-10-12 17:18:09 | 显示全部楼层 |阅读模式

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

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

x

#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=_findfirst(strcat(thePath,"/*"),&fa))==-1L)
{fprintf(stderr,"The path %s is 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]=".";
print("计算中...\n");
findALLCodes(path);
findALLDirs(path);
printf("目前你总共写了%ld行代码!\n\n",total);
system("pause");
return 0;
}
最佳答案
2020-10-13 23:42:40
你的程序共有三个错误,已经帮你修改了,看程序中的注释处


  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.     if ((fp=fopen(filename,"r"))==NULL)
  17.     {
  18.         fprintf(stderr,"Can not open the file:%s\n",filename);
  19.         return 0;
  20.     }
  21.     while ((temp=fgetc(fp))!=EOF)
  22.     {
  23.         if (temp=='\n')
  24.         {
  25.                 count++;
  26.         }
  27.     }
  28.     fclose(fp);
  29.     return count;
  30. }

  31. void findALLCodes(const char *path)   // 定义函数多了一个分号
  32. {
  33.     struct _finddata_t fa;
  34.     long handle;
  35.     char thePath[MAX], target[MAX];

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

  46.     _findclose(handle);
  47. }

  48. void findALLDirs(const char *path)
  49. {
  50.     struct _finddata_t fa;    // 定义结构体类型与名称之间( struct 后面)少一个空格
  51.     long handle;
  52.     char thePath[MAX];

  53.     strcpy(thePath,path);
  54.     if((handle=_findfirst(strcat(thePath,"/*"),&fa))==-1L)
  55.     {
  56.         fprintf(stderr,"The path %s is wrong!\n",path);
  57.         return;
  58.     }
  59.     do
  60.     {
  61.         if(!strcmp(fa.name,".")||!strcmp(fa.name,".."))
  62.         continue;
  63.         if(fa.attrib==_A_SUBDIR)
  64.         {
  65.             sprintf(thePath,"%s/%s",path,fa.name);
  66.             findALLCodes(thePath);
  67.             findALLDirs(thePath);
  68.         }
  69.     }while (_findnext(handle,&fa)==0);
  70.         _findclose(handle);
  71. }

  72. int main()
  73. {
  74.     char path[MAX]=".";
  75.     printf("计算中...\n");    //printf()写成了print()
  76.     findALLCodes(path);
  77.     findALLDirs(path);
  78.     printf("目前你总共写了%ld行代码!\n\n",total);
  79.     system("pause");
  80.     return 0;
  81. }

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

使用道具 举报

 楼主| 发表于 2020-10-12 17:21:28 | 显示全部楼层
void findALLCodes(const char *path);这条代码下面那个大括号会被框起
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-12 20:18:22 | 显示全部楼层
语法错误呗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-12 20:42:37 | 显示全部楼层

哪错了呀
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-12 21:11:47 | 显示全部楼层

大哥 大哥 哪里错了呀
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-12 21:21:40 | 显示全部楼层
奔跑的小鸟11 发表于 2020-10-12 21:11
大哥 大哥 哪里错了呀

这是你自己敲得?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-12 21:38:19 | 显示全部楼层
巴巴鲁 发表于 2020-10-12 21:21
这是你自己敲得?

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

使用道具 举报

 楼主| 发表于 2020-10-12 21:40:09 | 显示全部楼层

不知道那个大括号为什么错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-13 21:06:55 | 显示全部楼层
巴巴鲁 发表于 2020-10-12 21:21
这是你自己敲得?

大哥 大哥 求支招啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-13 23:42:40 | 显示全部楼层    本楼为最佳答案   
你的程序共有三个错误,已经帮你修改了,看程序中的注释处


  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.     if ((fp=fopen(filename,"r"))==NULL)
  17.     {
  18.         fprintf(stderr,"Can not open the file:%s\n",filename);
  19.         return 0;
  20.     }
  21.     while ((temp=fgetc(fp))!=EOF)
  22.     {
  23.         if (temp=='\n')
  24.         {
  25.                 count++;
  26.         }
  27.     }
  28.     fclose(fp);
  29.     return count;
  30. }

  31. void findALLCodes(const char *path)   // 定义函数多了一个分号
  32. {
  33.     struct _finddata_t fa;
  34.     long handle;
  35.     char thePath[MAX], target[MAX];

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

  46.     _findclose(handle);
  47. }

  48. void findALLDirs(const char *path)
  49. {
  50.     struct _finddata_t fa;    // 定义结构体类型与名称之间( struct 后面)少一个空格
  51.     long handle;
  52.     char thePath[MAX];

  53.     strcpy(thePath,path);
  54.     if((handle=_findfirst(strcat(thePath,"/*"),&fa))==-1L)
  55.     {
  56.         fprintf(stderr,"The path %s is wrong!\n",path);
  57.         return;
  58.     }
  59.     do
  60.     {
  61.         if(!strcmp(fa.name,".")||!strcmp(fa.name,".."))
  62.         continue;
  63.         if(fa.attrib==_A_SUBDIR)
  64.         {
  65.             sprintf(thePath,"%s/%s",path,fa.name);
  66.             findALLCodes(thePath);
  67.             findALLDirs(thePath);
  68.         }
  69.     }while (_findnext(handle,&fa)==0);
  70.         _findclose(handle);
  71. }

  72. int main()
  73. {
  74.     char path[MAX]=".";
  75.     printf("计算中...\n");    //printf()写成了print()
  76.     findALLCodes(path);
  77.     findALLDirs(path);
  78.     printf("目前你总共写了%ld行代码!\n\n",total);
  79.     system("pause");
  80.     return 0;
  81. }

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

使用道具 举报

 楼主| 发表于 2020-10-15 22:43:32 | 显示全部楼层
风过无痕1989 发表于 2020-10-13 23:42
你的程序共有三个错误,已经帮你修改了,看程序中的注释处

额 能运行了 但是运行后不能读出代码行数
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-15 23:06:06 | 显示全部楼层
奔跑的小鸟11 发表于 2020-10-15 22:43
额 能运行了 但是运行后不能读出代码行数

你将第41行 : if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L) 改成下面的语句:

if((handle = _findfirst(strcat(thePath, "/*.cpp"), &fa)) != -1L)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-16 13:04:53 | 显示全部楼层
风过无痕1989 发表于 2020-10-15 23:06
你将第41行 : if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L) 改成下面的语句:

if ...

大佬  还是不行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-16 13:06:44 | 显示全部楼层

显示的是can‘t open the file
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-16 14:42:35 | 显示全部楼层
本帖最后由 风过无痕1989 于 2020-10-16 15:10 编辑
奔跑的小鸟11 发表于 2020-10-16 13:06
显示的是can‘t open the file


这是复制我发在 10楼的程序的运行结果

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

使用道具 举报

发表于 2020-10-16 14:56:18 | 显示全部楼层
奔跑的小鸟11 发表于 2020-10-16 13:06
显示的是can‘t open the file

对了,在你的文件包里不能有同名的EXE文件,否则需要运行的程序就有可能打不开

DEV运行时.jpg
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-16 15:26:07 | 显示全部楼层
提示你有错误,需要改正,比如标点要切换到英文输入。
你仔细对一下小甲鱼的作业就能发现
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-16 20:52:27 | 显示全部楼层
风过无痕1989 发表于 2020-10-16 14:56
对了,在你的文件包里不能有同名的EXE文件,否则需要运行的程序就有可能打不开

我这咋又有C 又有C++的啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-16 21:01:35 | 显示全部楼层
奔跑的小鸟11 发表于 2020-10-16 20:52
我这咋又有C 又有C++的啊

有,没有关系,有关系的是你要运行的那个是C,还是C++
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-16 21:10:32 | 显示全部楼层
奔跑的小鸟11 发表于 2020-10-16 20:52
我这咋又有C 又有C++的啊

我这里有 test.c、test.cpp,还有test2.c、test3.c、test4.c,这些是因为回答问题所需要而建立的,它们的存在(只要 test.exe 不存在就行,这里要说明一下, test.exe 并不一定不能存在,但有些时候它的存在就会出问题,所以,遇到文件不能打开,就应想到是它的存在,删除后再重新启动 DEV运行,就不会存在打不开的情况发生了),并不影响 test.c ( 或 test.cpp )的运行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 13:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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