青山星 发表于 2022-8-5 10:34:19

#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <字符串>
#include <stdlib.h>
#include <sys/stat.h>

#define 最大 256

长总计;

int countLines(const char *filename);
int isCode(const char *filename);
void findAllDirs(const char *path);

int countLines(const char *filename)
{
文件 *fp;
整型计数 = 0;
int temp;

if ((fp = fopen(filename, “r”)) == NULL)
      {
fprintf(stderr, “无法打开文件: %s\n”, 文件名);
返回 0;
      }

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

fclose(fp);

返回计数;
}

int isCode(const char *filename)
{
整型长度;

length = strlen(filename);
      
if (!strcmp(filename + (length - 2), “.c”))
      {
返回 1;
      }

      {
返回 0;
      }
}

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

if ((dp = opendir(path)) == NULL)
      {
fprintf(stderr, “path %s is error!\n”, path);
返回;
      }

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

if (!strcmp(“.”, entry->d_name) || !strcmp(“..”, entry->d_name))
继续;

如果 (S_ISDIR(statbuf.st_mode))
                {
findAllDirs(entry->d_name);
                }

                {
if (isCode(entry->d_name))
                        {
总计 += 计数线(入门级>d_name);
                        }
                }
      }

chdir(“..”);
closedir(dp);
}

int main()
{
字符路径 = “.”;

printf(“计算中...\n”);

findAllDirs(path);

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

返回 0;
}

LBZ_7kg 发表于 2022-8-5 10:38:58

1

Humble_ 发表于 2022-8-5 10:47:52

1

graph 发表于 2022-8-5 10:51:48

查看参考答案

折折星 发表于 2022-8-5 13:30:44

已完成训练

veyRoN02 发表于 2022-8-5 13:32:08

学习c语言第一天,打卡{:9_228:}

veyRoN02 发表于 2022-8-5 13:44:22

想问一下,为什么我的第一个代码不给计算结果呢,是哪里出问题了吗?

seres 发表于 2022-8-5 14:34:25

来看答案啦

刘子诺 发表于 2022-8-5 14:36:53

怎么翻译成中文?

0. 为什么我们说计算机其实是“二傻子”?
只懂0和1(二进制)
1. CPU 唯一认识的语言是什么语言?
机器语言
2. C 语言编写的源代码转换为汇编语言的过程叫什么?
编译
3. 编译型语言和解释型语言的本质区别是什么?
一个一行代码编译一次,一个整个代码一起编译
4. 在 Linux 系统上用 C 语言编译的可执行程序,是否能在 Windows 系统上执行?
大部分能
5. 解释型编程语言是如何实现跨平台的?
通过转化为字节码
6. 莫斯密码的原理其实是什么?
查表
7. 视频中小甲鱼“故弄玄虚”的那段密文还原后是什么内容(中文)?
I don't know SOS

omiga 发表于 2022-8-5 15:54:34

{:5_102:}

k.lmao 发表于 2022-8-5 16:07:26

build succeed了

小绿c 发表于 2022-8-5 16:29:49

1

longyue_miku 发表于 2022-8-5 16:40:23

查看答案

linjy-stupid 发表于 2022-8-5 17:07:15

答案

子木yuan 发表于 2022-8-5 19:03:06

查看参考答案

阿翀要考研 发表于 2022-8-5 19:26:27

求看

学习使我掉发 发表于 2022-8-5 19:33:04

1.二进制
2、解码
3.解释性语言需要解释器
4.可以
5.通过源代码通过对应的解释器解码
6.对应表查询

gyb1027 发表于 2022-8-5 19:47:05

附图

钻石玻璃 发表于 2022-8-5 20:08:10

查看答案

玩儿过得刚好 发表于 2022-8-5 20:37:23

计算中...
目前你总共写了 0 行代码!
页: 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 [1698] 1699 1700 1701 1702 1703 1704 1705 1706 1707
查看完整版本: S1E2:第一个程序 | 课后测试题及答案