66
0.计算机只能识别0和1
1.C语言
2.编译
3.编译型语言不需要由解释器翻译,而解释性语言需要
4.可以
5.不知道
#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;
}
已做
谢谢
"C:\Users\Windows10\Desktop\fishC\1 helloworld\test1\project.PNG"
查看参考答案
0
查看本帖隐藏内容
滴滴
1
测试题的答案:
第0题的答案是:计算机会根据你输入的命令来执行对应的操作,你叫它做啥,它就会做啥,一切听从您的指示
第1题的答案是:机器语言,或称为二进制指令:0和1
第2题的答案是:解释和编译
第3题的答案是:编译型语言需要将全部代码写完后,统一进行编译后再使用;解释性语言是逐步执行编译你输入的代码
第4题的答案是:可以执行,在windows系统的电脑上安装个虚拟机,虚拟机的系统用Linux的,就可以实现
第5题的答案是:在不同版本的电脑上配置好要执行文件的环境,再去试着执行这个程序
第6题的答案是:原理是查表,根据你输出的行为,去查看目录下记载的信息,一一对照获取正确的消息
第7题的答案是:懒得查
动动手:
第0题答案是:0,因为这个目录我一行代码都没写
101行代码
3
查看参考答案
多谢甲鱼
完成
感谢楼主无私奉献!
1.因为计算机只能读懂0和1;
2.编译
因为他只懂二进制