时光战歌 发表于 2021-8-25 16:01:00

1

XuJIEALL 发表于 2021-8-25 16:16:15


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

#define MAX      256

long total;

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, "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;
}

john19997 发表于 2021-8-25 16:50:46

多C多营养.

每天都要多喝水 发表于 2021-8-25 17:13:35

来学习的第一天

2385494816a 发表于 2021-8-25 17:18:31

666

STRANGER0824 发表于 2021-8-25 17:41:59

...

也无风雨也无晴8 发表于 2021-8-25 18:10:26

1.计算机只认识2进制
2.
3.语言转换
4.不能
5.解释方法一样
6.一定符号对应密码表
7.

01萧 发表于 2021-8-25 20:22:26

0:因为它只认识计算机语言
1:二进制
2:编译
3:不知道
4:不能
5:不知道
6:不知道
7:没看

临哒儿 发表于 2021-8-25 20:51:29

本帖最后由 临哒儿 于 2021-8-25 20:53 编辑

大骗子{:10_266:}为啥是零

suspective 发表于 2021-8-25 21:04:11

答案

梦荀 发表于 2021-8-25 21:38:21

回复

meow6320741 发表于 2021-8-25 22:43:33

123

alin527 发表于 2021-8-25 22:48:13

我来看答案 谢谢哥哥

bszs 发表于 2021-8-26 00:15:56

102

开水一方 发表于 2021-8-26 09:05:31

本帖最后由 开水一方 于 2021-8-26 10:17 编辑

1.因为计算机的“大脑”是 CPU,CPU 负责计算机大部分日常的计算功能,而 CPU 原理上只认识 0 和 1。简而言之,CPU只认识二进制数。
2.机器语言.
3.编译.
4.对于 CPU 而言,编译型语言是将源代码先通过编译器编译为 CPU 认识的机器码(可执行文件),此后 CPU 随时都可以直接执行编译后的机器码;而解释型语言则不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行。
5.不能。因为可执行文件在执行之前,操作系统要有一些准备工作,因为不同的操作系统,准备工作是不同的,所以可执行文件的格式不完全相同。比如 Windows 上大部分可执行文件为 PE 格式,而 Linux 上大部分可执行文件为 ELF 格式。格式不同导致了不同的可执行文件无法跨平台直接使用.
6.解释型编程语言为每个操作系统专门定制一个解释器作为中转,因此解释器只需提供一个统一的入口即可.
7.查表.
8.QINMENCHENDIRENCHIFANSHIFADONGJINGONG.亲们 趁敌人吃饭时发动进攻。


星兔 发表于 2021-8-26 09:53:13

答案

R18lady 发表于 2021-8-26 10:35:17

甲鱼真帅

HeJet 发表于 2021-8-26 10:47:11

回复

alashan7 发表于 2021-8-26 10:56:16

KAN DA AN

DaiNing810 发表于 2021-8-26 11:36:57

答案
页: 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 [1335] 1336 1337 1338 1339 1340 1341 1342 1343 1344
查看完整版本: S1E2:第一个程序 | 课后测试题及答案