革命年 发表于 2020-7-29 11:31:26

C语言错误

我照着小甲鱼的代码复制的,结果还是错了,求解答
#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;
}

zltzlt 发表于 2020-7-29 11:33:40

直接复制小甲鱼的试试?

sunrise085 发表于 2020-7-29 11:34:21

什么错误??

Twilight6 发表于 2020-7-29 11:38:33




我这里运行正常呀,不报错,你是不是抄错了 Linux 和 Windows 代码要看清哈

革命年 发表于 2020-7-29 11:47:30

zltzlt 发表于 2020-7-29 11:33
直接复制小甲鱼的试试?

我就是复制了他的

革命年 发表于 2020-7-29 11:48:46

Twilight6 发表于 2020-7-29 11:38
我这里运行正常呀,不报错,你是不是抄错了 Linux 和 Windows 代码要看清哈

没有呀,我看着上面白纸黑字的写着windows系统

Twilight6 发表于 2020-7-29 11:50:31

革命年 发表于 2020-7-29 11:48
没有呀,我看着上面白纸黑字的写着windows系统



那报错内容是什么呢?

革命年 发表于 2020-7-29 11:51:44

Twilight6 发表于 2020-7-29 11:50
那报错内容是什么呢?

说第88行错了

Twilight6 发表于 2020-7-29 11:52:42

革命年 发表于 2020-7-29 11:51
说第88行错了



应该没错吧,你重新复制运行试试看?

Twilight6 发表于 2020-7-29 11:55:22

本帖最后由 Twilight6 于 2020-7-29 11:56 编辑

革命年 发表于 2020-7-29 11:51
说第88行错了



你应该是因为一个文件夹下有多个 c 语言代码文件?

把其他代码文件先移出文件夹,或者将代码全部清空,因为 C 语言一个项目只能有一个 main

你清空了其他代码后,继续执行你的代码即可


xiaosi4081 发表于 2020-7-29 14:05:50

你那个目录下只能有一个main()函数

永恒的蓝色梦想 发表于 2020-8-13 22:24:34

xiaosi4081 发表于 2020-7-29 14:05
你那个目录下只能有一个main()函数

抄袭这么有意思?
页: [1]
查看完整版本: C语言错误