Dr.SEVEN 发表于 2023-9-9 19:03:06

I love fishc

呵呵儿呵呵 发表于 2023-9-9 21:04:12

Hello world!

hsml31 发表于 2023-9-9 21:13:25

anwser

Lnhow 发表于 2023-9-9 21:58:27

1

无幽a 发表于 2023-9-10 09:15:04

只能听懂一种语言
计算机语言
编译
一个是直达,一个有转站

通过解释器
找代码看指令

下烦人 发表于 2023-9-10 09:39:20

已完成测试题

2437977819 发表于 2023-9-10 11:50:12

good

sanfish 发表于 2023-9-10 11:51:07

都是英语哎

Richard-YPY 发表于 2023-9-10 15:30:46

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>

#define MAX_PATH 256

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, "无法打开文件:%s\n", filename);
      return 0;
    }

    while ((temp = fgetc(fp)) != EOF)
    {
      if (temp == '\n')
      {
            count++;
      }
    }

    fclose(fp);

    return count;
}

void findAllCodes(const char *path)
{
    DIR *dir;
    struct dirent *entry;
    char targetPath, filePath;

    if ((dir = opendir(path)) == NULL)
    {
      fprintf(stderr, "无法打开路径:%s\n", path);
      return;
    }

    while ((entry = readdir(dir)) != NULL)
    {
      sprintf(filePath, "%s/%s", path, entry->d_name);

      if (entry->d_type == DT_REG && strstr(entry->d_name, ".c") != NULL)
      {
            int fileCount = countLines(filePath);
            printf("文件:%s,行数:%d\n", filePath, fileCount);
      }
      else if (entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
      {
            sprintf(targetPath, "%s/%s", path, entry->d_name);
            findAllCodes(targetPath);
      }
    }

    closedir(dir);
}

void findAllFiles(const char *path)
{
    DIR *dir;
    struct dirent *entry;
    char targetPath;

    if ((dir = opendir(path)) == NULL)
    {
      fprintf(stderr, "无法打开路径:%s\n", path);
      return;
    }

    while ((entry = readdir(dir)) != NULL)
    {
      sprintf(targetPath, "%s/%s", path, entry->d_name);

      if (entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
      {
            findAllCodes(targetPath);
            findAllFiles(targetPath);
      }
    }

    closedir(dir);
}

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

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

    findAllCodes(path);
    findAllFiles(path);

    return 0;
}

ycrin 发表于 2023-9-10 15:34:06

.

赤坂龙之介. 发表于 2023-9-10 15:48:12

赤坂龙之介

柿子HUA 发表于 2023-9-10 17:39:31

报错原因找不着怎么办

Hj7677 发表于 2023-9-10 18:27:15

1111

2737173811 发表于 2023-9-10 19:47:39

查看参考答案

Melissa_L 发表于 2023-9-10 20:17:03

i

meimeng920 发表于 2023-9-10 20:53:04

太难了

JokerHYX197 发表于 2023-9-10 21:24:33

1

Bluest16 发表于 2023-9-10 23:00:42

woxiangkandana

刘蓉呀! 发表于 2023-9-10 23:36:02

daan

野原琳之父 发表于 2023-9-11 10:23:12

123
页: 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 [1942] 1943 1944 1945 1946 1947 1948 1949 1950 1951
查看完整版本: S1E2:第一个程序 | 课后测试题及答案