657302413 发表于 2021-9-8 17:07:03

#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX          256

long total;

int countLines(const char *fliename);
void findAllCodes(const char *path);
void findAllFilles(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;
}

void findAllCodes(const char *path)
{
                struct _finddata_t fa;
                long handle;
                char thePath,target;
               
                strcpy(thePath,path);
                if((handle = _findfirst(strcat(thePath,"/*.c"),&fa))!=-1L)
                {
                                do
                                {
                                                sprintf(target,"%s/%s",path,fa.name);
                                                total += countLines(target);
                                }while (_findnext(handle,&fa) == 0);
                }
               
                _findclose(handle);
}

void findALLDirs(const char *path)
{
                struct _finddata_t fa;
                long handle;
                char thePath;
               
                strcpy(thePath,path);
                if((handle = _findfirst(strcat(thePath,"/*"),&fa)) == -1L)
                {
                                fprintf(stderr,"The path %s is wrong!\n",path);
                                return;
                }
               
                do
                {
                                if (!strcmp(fa.name, ".") || !strcmp(fa.name,".."))
                                                continue;
                                       
                                if (fa.attrib == _A_SUBDIR)
                                {
                                                sprintf(thePath, "%s/%s", path, fa.name);
                                                findAllCodes(thePath);
                                                findALLDirs(thePath);
                                }
                }while (_findnext(handle,&fa)==0);
               
                _findclose(handle);
}

int main()
{
                char path =".";
               
                printf("计算中...\n");
               
                findAllCodes(path);
                findALLDirs(path);
               
                printf("目前你总共写了 %ld 行代码!\n\n",total);
                system("pause");
               
                return 0;
}

梦开始的地方@ 发表于 2021-9-8 17:40:13

第一次学习

lixiaoyan 发表于 2021-9-8 18:11:24

;

wananzuiqingfen 发表于 2021-9-8 19:01:38

x

jeremy334567 发表于 2021-9-8 19:13:27

.

lkhannn 发表于 2021-9-8 19:27:46

{:5_102:}

码农号 发表于 2021-9-8 19:38:57

感谢

码农号 发表于 2021-9-8 19:39:29

感谢

qq442366367 发表于 2021-9-8 20:07:51

答案是啥

1545323778 发表于 2021-9-8 20:29:16

1111

头秃小白 发表于 2021-9-8 20:37:39

0、只懂二进制的0和1
1、机器语言
2、编译
3、直接编译、不直接编译
4、能
5、将字节码发送给解释器,由解释器逐句翻译给CPU
6.查表
7.亲们,趁敌人吃饭发动进功。

小张要学习 发表于 2021-9-8 20:38:02

{:5_109:}

可惜 发表于 2021-9-8 21:07:30

1

LinRon 发表于 2021-9-8 21:16:50

0.只认识二进制的0和1
1.机器语言
2.编译
3.前者直接编译出cpu可执行文件,后者只是编译成中间代码后借助解释器来逐句编译成机器语言
4.能
5.借助解释器
6.查表
7.......趁敌人吃饭时发动进攻

柚芯 发表于 2021-9-8 21:49:05

1

520zjw 发表于 2021-9-8 21:59:42

0.计算机只看的懂特定的语言
1.1和0
2.编译
3.需要编译的过程
4.可以
5.不知道
6.对照表
。。

l14564 发表于 2021-9-8 22:00:08

0.计算机是用二进制   只能直接读取0和1
1.CPU唯一认识机器语言
2.编译
3.是否直接编译成机器语言被CPU读取
4.可以,他们的内核都是用C语言编写
5.解释型不会先编译成机器语言,需要经过中间代码,用解释器才可以被CPU读取
6.节奏长短和数量对应英文字母和数字
7.亲们趁敌人吃饭时发动进攻

水浮轻舟 发表于 2021-9-8 22:42:38

上传不了图片orz

ply小童鞋 发表于 2021-9-8 23:01:29

偷瞄

overthinkinger 发表于 2021-9-8 23:07:16

查看参考答案
页: 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 [1356] 1357 1358 1359 1360 1361 1362 1363 1364 1365
查看完整版本: S1E2:第一个程序 | 课后测试题及答案