鱼C论坛

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

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

    [复制链接]
发表于 2018-12-10 14:58:30 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
123123123
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 15:24:34 | 显示全部楼层
看答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 15:32:20 | 显示全部楼层
图一时之快先看答案,你将失去一次锻炼的机会!QaLrA5qFM_
u(oI{=C4h8>~-!vfjPn_c739V5,.
请先自己思考和动手,再回复查看参考答案。4H`
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 16:01:46 | 显示全部楼层
0、只能识别0-1
1、机器语言
2、编译
3、机器能否识别
4、能-C可移植性
5、C可移植性
6、0-1编码对应
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 19:59:30 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-10 20:52:20 | 显示全部楼层
#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 findAIICodes(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 findAIICodes(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);
                        findAIICodes(thePath);
                        findALLDirs(thePath);
                }
        }while (_findnext(handle,&fa)==0);

        _findclose(handle);
}

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

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

        findAIICodes(path);
        findALLDirs(path);

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

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

使用道具 举报

发表于 2018-12-10 21:43:27 | 显示全部楼层

#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("目前你总共写了 %d 行代码!\n\n",total);
                system("pause");
               
                return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 22:09:14 | 显示全部楼层
哎,确实挺难的呢!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 23:01:16 | 显示全部楼层
偷看,嘻嘻
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 23:42:57 | 显示全部楼层

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-11 09:23:09 | 显示全部楼层
好难打。打字太慢了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-11 13:19:20 | 显示全部楼层
答案
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-11 13:47:58 | 显示全部楼层
查看
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-11 18:42:39 | 显示全部楼层
答案
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-11 19:36:24 | 显示全部楼层
测试题答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-12 13:21:43 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-12 14:12:35 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

使用道具 举报

发表于 2018-12-12 15:59:12 | 显示全部楼层
哦哦哦哦哦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-12 19:37:30 | 显示全部楼层
加油哦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-27 14:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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