鱼C论坛

 找回密码
 立即注册
查看: 1518|回复: 9

关于小甲鱼学c系列的第一个作业问题

[复制链接]
发表于 2021-9-23 16:23:41 | 显示全部楼层 |阅读模式

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

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

x
  大佬们,带你学c带你飞的第一份课后作业,那个一大串代码我打完了,但是到了运行的时候一直说findALLDirs没有声明,请问要如何处理。(检查了好几遍了跟小甲鱼上面的一样,就这里会出问题,但是删除这一段又失去功能了)用的是Dev-c++。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-23 16:25:35 From FishC Mobile | 显示全部楼层
谁都不是神仙,谁知道你在说啥啊,简直就是天文
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-23 16:28:17 | 显示全部楼层
检查了好几遍了跟小甲鱼上面的一样
肯定不一样,一样为什么不能用?
再非常认真的多检查几遍,一个字符一个字符的检查
在检查几遍后还是检查不出来的话,把代码发出来,我们帮你检查
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-23 16:45:44 | 显示全部楼层
本帖最后由 jackz007 于 2021-9-23 16:46 编辑

       C语言的函数、变量在使用前必须要进行定义或声明,你这种情况应该是函数 findALLDirs() 在调用前没有提前定义或声明。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-23 20:26:05 | 显示全部楼层
看一看"L"的大小写。我也是检查了好多遍,最后发现是大小写问题。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-23 21:48:24 | 显示全部楼层
代码发出来,我们来查
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-24 07:54:14 | 显示全部楼层
希望·别秃 发表于 2021-9-23 21:48
代码发出来,我们来查

#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] = ".";
               
                printf("计算中...\n");
               
                findAllCodes(path);
                findALLDirs(path);
               
                printf("目前你总共写了 %ld 行代码! \n\n", total);
                system("pause");
               
                return 0;       
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-24 07:59:08 | 显示全部楼层
#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] = ".";
               
                printf("计算中...\n");
               
                findAllCodes(path);
                findALLDirs(path);
               
                printf("目前你总共写了 %ld 行代码! \n\n", total);
                system("pause");
               
                return 0;       
}

昨天发不出来图片,今天才想起来发代码,抱歉了各位,我实在是检查不出来,望各位指正。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-24 16:17:36 From FishC Mobile | 显示全部楼层
l的大小写吧,我第一次也是这样,睡了一觉,第二天在看发现了;统一改成大写或小写,应该就可以编译了吧。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-25 09:25:06 | 显示全部楼层

方法名写的是findAllDirs,是小写的l。调用写的是findALLDirs,是大写的L。主函数也是大写。一直就可以了。我前面就说了大小写,你可以改一下试试对不对。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-22 09:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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