tqsdyy 发表于 2020-9-4 17:49:37

d,an

Vincent_Hong 发表于 2020-9-4 19:51:49

计算机只认识数字
机器语言
编译
前者是面向过程的语言,后者是面向对象的语言

jamallin 发表于 2020-9-4 20:37:45

#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;
}

本物的物语 发表于 2020-9-4 20:40:07

babakaka 发表于 2020-9-4 20:59:20

计算中

hentibin 发表于 2020-9-4 21:59:45

(⊙o⊙)

白shironeko 发表于 2020-9-4 22:12:54

我要答案

某中二绅士 发表于 2020-9-4 23:02:40

不看答案真不会,老说我1楼缺了

vugiiuhi 发表于 2020-9-5 00:31:10

1

cl624850 发表于 2020-9-5 07:35:25

因为计算机只能执行

1904360520 发表于 2020-9-5 09:11:07

亲们趁敌人吃饭时发动进攻

Azir先生 发表于 2020-9-5 11:38:21

答案

同意阅读 发表于 2020-9-5 12:48:19

我这边编译的时候一堆错误{:5_90:}

lmyer 发表于 2020-9-5 14:22:16

1

wang1020372527 发表于 2020-9-5 14:59:37

膜拜大佬

默奈 发表于 2020-9-5 16:03:30

0.因为CPU只懂得二进制的0和1。
1.机器语言
2.编译
3.编译型语言最终翻译成机器语言,解释型语言不直接编译成机器语言。
4.可以
5.解释型语言将源代码转换成中间代码,然后发送给解释器,由解释器逐句翻译给CPU来执行。
6.查表
7.亲们趁敌人吃饭时发动进攻

嘿哈哈 发表于 2020-9-5 16:35:30

0.他只能识别二进制码

1.机器语言

2.编译

3.

4.可以

5.

6.查找密码表

7.qinmenchendirenchifanshifadongjingong
亲们趁敌人吃饭时发动进攻

Wei_E 发表于 2020-9-5 16:59:21

0

季夏 发表于 2020-9-5 17:00:49

第一次照着代码抄完之后,出了好多错。检查第一遍之后,运行结果不对。等检查过两三次,发现了几处编译器没有指出的语法或者其他错误,等自己觉得和答案代码一模一样之后,运行结果还是不对。

fynb 发表于 2020-9-5 17:15:47

666
页: 829 830 831 832 833 834 835 836 837 838 [839] 840 841 842 843 844 845 846 847 848
查看完整版本: S1E2:第一个程序 | 课后测试题及答案