鱼C论坛

 找回密码
 立即注册
楼主: 小甲鱼

[课后作业] S1E2:第一个程序 | 课后测试题及答案

    [复制链接]
发表于 2020-10-20 15:08:36 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
好!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 15:21:31 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 15:43:23 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 16:13:17 | 显示全部楼层
本帖最后由 careeristdream 于 2020-10-20 16:24 编辑

代码复制运行之后,为什么显示是0行
捕获.PNG
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 17:03:42 | 显示全部楼层
本帖最后由 a残梦 于 2020-10-20 17:10 编辑

xercisc.c:蕃1缄救iountLines中:
xGIC1se.c: 28:错送:EOP'未声明(在此面数内第一次使用)
eerise--58:M溢︰一熟次出现每个未声明的标识符在其
exercise.c:_在堃数findAlIDirs中:
exercise.c: 83:错误∶sles'未声明(在此函数内第一次使用)
exercise.c:84:_错误expectedbeforetoken
exercise.c:在函数ain’中:
exercise.C:蕴播:廷tdIbefore"
exercise.c:99:错误缺少结尾的”字符
exercise.c:99:25:警告:缺少结尾的..字符
exercise.c:106:错误expected:’before'token
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 17:06:24 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 17:24:13 | 显示全部楼层
错了
9HE@7U7LY31]H@]BPHZ6ST9.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 17:26:16 | 显示全部楼层
666
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 17:28:40 | 显示全部楼层
学习学习学习
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 17:48:19 | 显示全部楼层
求答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 18:38:17 | 显示全部楼层
66666666666
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 18:51:43 | 显示全部楼层
我想问一下,我到底哪错了,求大佬指点
错误.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 18:58:31 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 19:11:20 | 显示全部楼层
file:///C:/Users/Alex/Desktop/%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%202020-10-20%20190705.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 19:23:11 | 显示全部楼层
dd
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 19:54:19 | 显示全部楼层
6
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 19:54:50 | 显示全部楼层
好累啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 20:01:57 | 显示全部楼层
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdio.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)) != EOP)
        {
                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(stract(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(stract(thePath, "/*"), &fa)) == -1L)
        {
                fprintf(stderr, "The Path %s is wrong!\n",path);
                return;
        }

        do
        {
                if(!strcpm(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, 7fa) == 0);

        _findclose(handle);
}

int main()
{
        char path[MAX] = ".";

        printf("计算中...\n");

        findALLCodes(path);
        findALLDirs(path);

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

        return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-20 20:08:08 | 显示全部楼层
答案
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-20 20:20:38 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-2-1 05:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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