淡泊十年 发表于 2020-8-12 23:13:25

刚才是学C的课后作业

82        23        C:\Users\Lenovo\Desktop\未命名1.cpp        'findALLDirs' was not declared in this scope      这是为什么 我按上面打下来的然后改了好多次最后复制82行的也没用

baige 发表于 2020-8-12 23:14:50

发完整代码

baige 发表于 2020-8-12 23:15:28

本帖最后由 baige 于 2020-8-12 23:37 编辑

这种情况就是你其他地方抄错了,声明,定义都有可能函数名写错了

zltzlt 发表于 2020-8-13 06:58:38

可能是你抄错了,直接复制下面的代码看看行不行?


#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-8-13 08:00:26

后缀名储存成.c,再不行就复制,你是不是复制linux的了

乐乐学编程 发表于 2020-9-26 01:47:32

没有结帖,正好拿来练习练习

// 该程序必须在 C 编译器下运行,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);    // C要大写
    findALLDirs(path);

    printf("目前你总共写了 %ld 行代码! \n\n", total);
    system("pause");

    return 0;
}
页: [1]
查看完整版本: 刚才是学C的课后作业