小白不急躁 发表于 2025-8-13 19:08:42

0.因为计算机只能读懂二进制
1.汇编语言
2.编译
3.在与能不能让计算机秒懂
4.可以
5.翻译器
6.忘记啦
7.

lifacheng520 发表于 2025-8-14 10:55:09

看答案

qq839815224 发表于 2025-8-14 21:08:34

运行失败了

SHANGKEJIUSHUI 发表于 2025-8-16 16:13:03

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

HatsuneReimu 发表于 2025-8-16 20:28:59

来了

13978074582 发表于 2025-8-17 23:06:45

hh

哈之褚 发表于 2025-8-19 19:51:55

参考答案

461378836 发表于 2025-8-20 00:09:06

qwert

岂无白衣 发表于 2025-8-20 15:50:14

1

ding2025 发表于 2025-8-21 18:50:13

1

Marukovo 发表于 2025-8-22 16:19:29

0.二进制
1.机器语言
2.编译
3.
4.不能
5.
6.
7.亲们趁敌人吃饭时发动进攻

黑色柳丁C 发表于 2025-8-23 15:58:30

看看答案

小忆元 发表于 2025-8-23 21:57:05

做完题了看下答案

大囧耳蜗 发表于 2025-8-23 23:44:13

回复

kojihhh 发表于 2025-8-25 16:46:33

111111

洪荒少女01 发表于 2025-8-25 17:55:48

myl1 发表于 2025-8-26 11:31:32

111

2150603470 发表于 2025-8-26 19:00:01

查看参考答案

一颗朝天椒 发表于 2025-8-28 01:33:55

我看看怎么个事儿

啥子子路 发表于 2025-8-29 18:29:02

123
页: 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 [2111] 2112 2113 2114 2115 2116 2117 2118 2119 2120
查看完整版本: S1E2:第一个程序 | 课后测试题及答案