yzf666 发表于 2021-2-13 22:02:20

66

艾斯cream 发表于 2021-2-14 09:06:34

0.计算机只能识别0和1
1.C语言
2.编译
3.编译型语言不需要由解释器翻译,而解释性语言需要
4.可以
5.不知道

伯乐伯乐 发表于 2021-2-14 10:40:51

#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>

#define MAX 256

long total;

int countLines(const char *filename);
int isCode(const char *filename);
void findAllDirs(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;
}

int isCode(const char *filename)
{
      int length;

      length = strlen(filename);
      
      if (!strcmp(filename + (length - 2), ".c"))
      {
                return 1;
      }
      else
      {
                return 0;
      }
}

void findAllDirs(const char *path)
{
      DIR *dp;
      struct dirent *entry;
      struct stat statbuf;

      if ((dp = opendir(path)) == NULL)
      {
                fprintf(stderr, "The path %s is wrong!\n", path);
                return;
      }

      chdir(path);
      while ((entry = readdir(dp)) != NULL)
      {
                lstat(entry->d_name, &statbuf);

                if (!strcmp(".", entry->d_name) || !strcmp("..", entry->d_name))
                        continue;

                if (S_ISDIR(statbuf.st_mode))
                {
                        findAllDirs(entry->d_name);
                }
                else
                {
                        if (isCode(entry->d_name))
                        {
                              total += countLines(entry->d_name);
                        }
                }
      }

      chdir("..");
      closedir(dp);
}

int main()
{
      char path = ".";

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

      findAllDirs(path);

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

      return 0;
}

Ks开森 发表于 2021-2-14 10:53:01

已做

duragen 发表于 2021-2-14 11:49:33

谢谢

啾啾良 发表于 2021-2-14 12:07:39

"C:\Users\Windows10\Desktop\fishC\1 helloworld\test1\project.PNG"

温柔给了猫a 发表于 2021-2-14 12:25:59

查看参考答案

冰海 发表于 2021-2-14 12:38:29

0

上Q只为一人 发表于 2021-2-14 12:41:07

查看本帖隐藏内容

时之歌 发表于 2021-2-14 13:58:36

滴滴

Aihara233 发表于 2021-2-14 14:18:07

1

消逝之风 发表于 2021-2-14 14:28:46

测试题的答案:
第0题的答案是:计算机会根据你输入的命令来执行对应的操作,你叫它做啥,它就会做啥,一切听从您的指示

第1题的答案是:机器语言,或称为二进制指令:0和1

第2题的答案是:解释和编译

第3题的答案是:编译型语言需要将全部代码写完后,统一进行编译后再使用;解释性语言是逐步执行编译你输入的代码

第4题的答案是:可以执行,在windows系统的电脑上安装个虚拟机,虚拟机的系统用Linux的,就可以实现

第5题的答案是:在不同版本的电脑上配置好要执行文件的环境,再去试着执行这个程序

第6题的答案是:原理是查表,根据你输出的行为,去查看目录下记载的信息,一一对照获取正确的消息

第7题的答案是:懒得查

动动手:
第0题答案是:0,因为这个目录我一行代码都没写

teng15 发表于 2021-2-14 14:59:57

101行代码

likkkk 发表于 2021-2-14 15:00:49

3

郑茗中 发表于 2021-2-14 15:32:45

查看参考答案

KeepAmbious 发表于 2021-2-14 16:05:15

多谢甲鱼

CSevenOvO 发表于 2021-2-14 16:09:00

完成

is同学 发表于 2021-2-14 16:21:33

感谢楼主无私奉献!

衔尾蛇丶 发表于 2021-2-14 18:01:54

1.因为计算机只能读懂0和1;
2.编译

15845711 发表于 2021-2-14 18:55:33

因为他只懂二进制
页: 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 [1067] 1068 1069 1070 1071 1072 1073 1074 1075 1076
查看完整版本: S1E2:第一个程序 | 课后测试题及答案