m18191352667 发表于 2019-3-15 20:06:03

8388608?

晚睡早起达人 发表于 2019-3-15 22:15:34

第二节课打卡

吴先森哦 发表于 2019-3-16 08:19:40

参考答案

crz花开半夏 发表于 2019-3-16 13:28:00

66666666

1527484207 发表于 2019-3-16 15:04:43

摸个答案

云度曦 发表于 2019-3-16 15:36:59

第四第五个还是不太清楚

超级亮宝宝 发表于 2019-3-16 16:07:55

111

tereya 发表于 2019-3-16 16:25:26

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

喝牛奶的何牛奶 发表于 2019-3-16 18:09:12

{:5_90:}

热恋中的茶叶蛋 发表于 2019-3-17 09:21:33

加油

苍华木 发表于 2019-3-17 09:38:21

你一共写了109行代码

82457097 发表于 2019-3-17 12:06:26

瞅一哈

aloneKing 发表于 2019-3-17 13:39:14

111

xjc123 发表于 2019-3-17 13:50:28

1

stephe 发表于 2019-3-17 15:01:07

谢谢

宛若处子 发表于 2019-3-17 15:16:10

“查看答案”

DaK0122 发表于 2019-3-17 17:37:03

0.只能听懂一种语言
1.机器语言
2.编译
3.工作效率
4.
5.翻译器
6.查表
7.

a741136822 发表于 2019-3-17 17:52:18

看看答案

鱼c__枫 发表于 2019-3-17 18:42:25

1

堂灼丶 发表于 2019-3-17 19:45:16

7行
页: 259 260 261 262 263 264 265 266 267 268 [269] 270 271 272 273 274 275 276 277 278
查看完整版本: S1E2:第一个程序 | 课后测试题及答案