ok
我只能显示计算中,所以我自己学着写了新的#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define MAX_FILE_SIZE 10000
int count_lines(char *filename) {
FILE *file = fopen(filename, "r");
if (file == NULL) {
printf("无法打开文件 %s\n", filename);
return 0;
}
int count = 0;
char line;
while (fgets(line, sizeof(line), file) != NULL) {
count++;
}
fclose(file);
return count;
}
int count_lines_recursive(char *dir_path) {
DIR *dir = opendir(dir_path);
if (dir == NULL) {
printf("无法打开目录 %s\n", dir_path);
return 0;
}
int total_lines = 0;
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
char entry_path;
sprintf(entry_path, "%s/%s", dir_path, entry->d_name);
struct stat entry_info;
if (stat(entry_path, &entry_info) == -1) {
printf("无法获取文件信息:%s\n", entry_path);
continue;
}
if (S_ISDIR(entry_info.st_mode)) {
// 忽略 "." 和 ".." 目录
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
// 递归处理子目录并累加代码行数
total_lines += count_lines_recursive(entry_path);
} else if (S_ISREG(entry_info.st_mode) && strstr(entry->d_name, ".exe") == NULL) {
// 处理普通文件,排除 .exe 文件
int lines = count_lines(entry_path);
printf("%s: %d 行\n", entry_path, lines);
total_lines += lines;
}
}
closedir(dir);
return total_lines;
}
int main() {
char current_dir;
if (getcwd(current_dir, sizeof(current_dir)) == NULL) {
printf("无法获取当前目录\n");
return 1;
}
printf("当前目录:%s\n", current_dir);
printf("开始统计代码行数...\n");
int total_lines = count_lines_recursive(current_dir);
printf("所有目录中代码行数的总和为:%d\n", total_lines);
printf("统计完成!\n");
return 0;
}
S1E2:第一个程序 | 课后测试题及答案 [修改]
HAHA
AA
学习
查看
1
1
答案
本帖最后由 clyenc 于 2024-2-16 11:56 编辑
0、因为它只认识0和1
1、机器语言(二进制码)
2、编译
3、编译执行的过程不同,编译型语言将源代码编译成汇编指令,再将汇编指令编译成机器码由cpu执行,解释型语言是将源代码转换成中间语言,再由解释器将中间语言编译成机器码由cpu执行
4、看情况吧,有些需要经过一定的修改
5、将源代码转换成中间语言实现跨平台
6、通过点横的组合,每一种组合对应唯一一个符号
7、qin men chen di ren chi fan shi fa dong jin gong
看答案
/*
0、计算机只懂二进制码
1、机器码
2、编译
3、编译型语言编译完后是机器码计算机可直接读取,解释型语言运行哪句前需要先通过解释器机器才能读懂,每次都需要”解释“过程
4、不可以
5、只需要解释器跨平台适配
6、排列组合
7、
*/
鱼C有你更精彩^_^
加油
0.无法直接执行指令
1.二进制的0和1
2编译
3.是否直接编译成机器码
4.可以
5.将源代码转化为中间代码,交给解释器来执行
6.查表
7.
1
查看
1
1