拖延症大叔 发表于 2020-2-12 16:51:10

S1E2上来就不行了啊。。。求大神解答呀。。

本帖最后由 拖延症大叔 于 2020-2-12 17:27 编辑

windows下抄的代码运行结果是202。。。复制作业里面的代码运行也是202。。。

哪位大神能告诉我哪出毛病了吗?小甲鱼截图显示的是101。。。{:10_266:}



#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, target;
      
      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;
      
      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 = ".";
      
      printf("计算中...\n");
      
      findAllCodes(path);
      findALLDirs(path);
      
      printf("目前你总共写了 %ld 行代码!\n\n", total);
      system("pause");
      
      return 0;
}

一个账号 发表于 2020-2-12 16:57:55

贴代码

qiuyouzhi 发表于 2020-2-12 17:11:42

不贴代码,没有人会知道你要表达什么

召唤风云 发表于 2020-2-12 19:44:39

我不懂你什么意思。

召唤风云 发表于 2020-2-12 20:58:27

我懂你的问题了,这是一个软件,可以数你所有的代码的行数,是所有,如果你还有其他的代码的话,他也会一起计算进去。如果一直都是101的话,那还有什么用?
页: [1]
查看完整版本: S1E2上来就不行了啊。。。求大神解答呀。。