鱼C论坛

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

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

    [复制链接]
发表于 2020-2-27 20:16:52 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
统计当前目录及所有子目录下,C 语言源文件的代码总行数,为0!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-27 20:29:15 | 显示全部楼层
已完成第一课练习!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

发表于 2020-2-27 20:39:05 | 显示全部楼层
0. 计算机只能看懂2进制
1.机器语言
2.编译
3.编译型语言把源代码编译成机器语言,解释性语言将源代码转换成中间代码,再发送给解译器翻译给CPU执行
4.不可以吧。
5.
6.查表
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-27 20:50:34 | 显示全部楼层
初来乍到
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-27 21:12:49 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-27 21:28:47 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-27 21:30:02 | 显示全部楼层
0.因为计算机会有很多Bug出现
1.C语言
2.编译
3.解释型语言不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行。编译型语言直接编译成机器码
4.不可以
5.解释型语言不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行
6.查表
7.亲们趁敌人吃饭时发动进攻
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

发表于 2020-2-27 22:50:29 | 显示全部楼层
感谢感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-27 23:05:58 | 显示全部楼层
学习打卡
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 00:03:29 | 显示全部楼层
0.计算机只认识0、1
1.机器语言
2.编译
3.编译型:直接输出cpu可执行代码;解释型:不能直接输出cpu可执行代码
4.能
5.中间码,需用平台的解释器解释后方可让cpu执行
6.查表
7.哈哈哈
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 00:17:17 | 显示全部楼层

#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;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 00:42:17 | 显示全部楼层
  1. #include<io.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>

  5. #define MAX 256

  6. long total;

  7. int countLines(const char *filename);
  8. void findAllCodes(const char *path);
  9. void findALLFiles(const char *path);

  10. int countLines(const char *filename)
  11. {

  12.     FILE *fp;
  13.     int count = 0;
  14.     int temp;

  15.     if((fp = fopen(filename,"r")) == NULL)
  16.     {
  17.         fprintf(stderr,"Can not open the file:%s\n",filename);
  18.         return 0;
  19.     }

  20.     while ((temp = fgetc(fp)) != EOF)
  21.     {
  22.         if(temp == '\n')
  23.         {
  24.             count ++;
  25.         }
  26.     }

  27.     fclose(fp);

  28.     return count;
  29. }

  30. void findAllCodes(const char *path)
  31. {
  32.     struct _finddata_t fa;
  33.     long handle;
  34.     char thePath[MAX],target[MAX];

  35.     strcpy(thePath,path);
  36.     if((handle = _findfirst(strcat(thePath,"/*.c"),&fa)) != -1L)
  37.     {
  38.         do
  39.         {
  40.             sprintf(target,"%s/%s",path,fa.name);
  41.             total += countLines(target);
  42.         }while (_findnext(handle,&fa) == 0);
  43.     }

  44.     _findclose(handle);
  45. }

  46. void findALLDirs(const char *path)
  47. {
  48.     struct _finddata_t fa;
  49.     long handle;
  50.     char thePath[MAX];

  51.     strcpy(thePath,path);
  52.     if((handle = _findfirst(strcat(thePath,"/*"),&fa)) == -1L)
  53.     {
  54.         fprintf(stderr,"The path %s is wrong!\n",path);
  55.         return;
  56.     }

  57.     do
  58.     {
  59.         if(!strcmp(fa.name,".")|| !strcmp(fa.name,".."))
  60.             continue;

  61.         if( fa.attrib == _A_SUBDIR)
  62.         {
  63.             sprintf(thePath,"%s/%s",path,fa.name);
  64.             findAllCodes(thePath);
  65.             findALLDirs(thePath);
  66.         }
  67.     }while (_findnext(handle,&fa) == 0);

  68.     _findclose(handle);
  69. }

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

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

  74.     findAllCodes(path);
  75.     findALLDirs(path);

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

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

使用道具 举报

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

使用道具 举报

发表于 2020-2-28 11:02:24 | 显示全部楼层
想要看答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 11:28:18 | 显示全部楼层
只懂二进制

忘了

后者给电脑时要多一步翻译

不能

忘了

忘了

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

使用道具 举报

发表于 2020-2-28 11:36:44 | 显示全部楼层
奥利给干了!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 11:44:59 | 显示全部楼层
我要答案啊!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 12:41:14 | 显示全部楼层
查看答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-11-14 12:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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