鱼C论坛

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

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

    [复制链接]
发表于 2019-3-6 17:52:33 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
对一下答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-6 23:15:08 | 显示全部楼层
答案
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-3-7 00:50:44 | 显示全部楼层
#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 256

总数;


int countLines(const char * filename);
void findAllCodes(const char * path);
void findAllFiles(const char * path);

int countiLines(const char * filename)
{
        FILE * fp;
        int count = 0;
        int temp;

        if ((fp = fopen_s(filename, "r") ) == NULL)
        {
                fprintf(stderr, "无法打开文件:%s\n", filename);
               
                return 0;
        }
        while ((temp = fgetc(fp)) != EOF)
        {
                if (temp == '\n')
                {
                        总数++;
                }
        }
        FCLOSE(fp);
       
        return 总数;

}

void findAllCodes(const char * path)
{
        struct _finddata_t fa;
        int handle;
        char thePath[MAX], 目标[MAX],总计[MAX];
       

        strcpy_s(thePath, path);
        if ((handle = _findfirst(strcat_s(thePath, "\*。c"), &fa)) != -1L)
        {
               
                {
                        sprintf_s(目标,"%s/%s",path,fa.name);
                        总计+= countLines(目标);

                }while (_findnext(handle, &fa) == 0);
        }

        _findclose(handle);

}


void findAllDirs(const char* path)
{
        struct _finddata_t fa;
        int handle;
        char thePath[MAX];

        strcpy_s(thePath, path);
        if ((handle = _findfirst(strcat_s(thePath, "/ *"), &fa)) == -1L)
        {
                fprintf(stderr, "路径%s错了!\n", thePath);
                return;

        }

       
        {
                if (!strcmp(fa.name,"。") || !strcmp(fa.name,".."))

                if (fa.attrib == _A_SUBDIR)
                {
                        sprintf_s(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", 总计);
       
        system("pause");

        return 0;


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

使用道具 举报

发表于 2019-3-7 02:21:00 From FishC Mobile | 显示全部楼层
打卡!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-3-7 05:00:56 From FishC Mobile | 显示全部楼层
qinmenchendirenchifgshfanonGwingong
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 06:07:45 From FishC Mobile | 显示全部楼层
不会啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 08:28:45 | 显示全部楼层
666666666666666
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 08:51:40 | 显示全部楼层
回复回复
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 09:49:40 | 显示全部楼层
测试题
0
因为计算机只认识0 1 这样的二进制机器码
1
机器语言
2
编译
3
编译型语言直接通过编译器编译成机器语言送给计算机
而解释型语言首先编译成中间代码 再通过解释器一句一句解释给计算机
4
阔以吧  毕竟C语言可移植性强
5
通过中间代码送给不同的解释器吧  我猜
6
莫斯密码的原理其实就是编码
7
I love FishC.com
dds
0
#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
回复 支持 反对

使用道具 举报

发表于 2019-3-7 13:57:30 | 显示全部楼层
查看答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 14:57:36 | 显示全部楼层
111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-3-7 15:43:54 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-3-7 16:48:14 | 显示全部楼层
0
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-3-7 21:24:46 | 显示全部楼层
看看啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 21:47:57 | 显示全部楼层
第一次作业
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-8 11:46:46 | 显示全部楼层
感谢小甲鱼的良苦用心,新人小白拜谢!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-8 12:11:06 | 显示全部楼层
1111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-3-8 12:38:18 | 显示全部楼层
小甲鱼我爱你
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-8 13:48:51 | 显示全部楼层
0.只会读取
1.机器码
2.C语言编程
3.解释型语言不会直接编译成机器码,要经过转换器
4.能
5.由字节码发到解释器
6.查找指令表
7.qinmen nnhend lrend hlfan shlf adong jlngd ag
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-8 16:04:02 | 显示全部楼层
zz
QQ截图20190308160259.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-1 16:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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