丙醇同学 发表于 2023-7-30 16:36: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 *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;
}

lei2384203995 发表于 2023-7-30 17:21:29

1

K1kuchiyo 发表于 2023-7-30 19:45:54

看答案咯{:5_90:}

我是陈平安 发表于 2023-7-30 21:28:20

{:9_225:}

沐雨尘枫 发表于 2023-7-31 14:00:14

感谢分享

dyxlovejwf 发表于 2023-7-31 14:27:19

查看参考答案

吴同学wxr 发表于 2023-7-31 15:41:43

谭仁韬 发表于 2023-7-31 16:21:07

11

xaio61008 发表于 2023-7-31 16:36:20

1

Frank66s 发表于 2023-7-31 16:46:15

0

七月听雨眠 发表于 2023-7-31 21:08:26

测试回复

Fix 发表于 2023-7-31 22:08:55

朕想知道

jOyceee 发表于 2023-7-31 23:27:56

0. 因为计算机只读得懂 机器语言
1 机器语言
2 编译
3. 高级语言是否编译成机器码
4. 大概率可以
5
6. 查表

LGoes 发表于 2023-8-1 14:04:28

1

kelianyin 发表于 2023-8-1 14:53:04

0因为计算机只认识0和1,每一步的操作都需要我们发出指令才能运行。识别数据类型,存放数据都需要我们制定好规则。

1 机器语言。也就是可执行文件,windows.exe ,可以被cpu直接执行。

2编译。

3 转译出来的代码不同,编译型语言转译成机器语言,解释型语言转译成字节码,再由字节码发送给解释器,最后再发送给cpu。结果是,编译型只认当前cpu所在系统,解释型语言可实现跨平台特性。

4 不能。因为c语言不是跨平台的语言,在windows系统上运行时需要修改一部分代码。

5 通过将代码转化为字节码,再传输到解释器,逐句翻译,最后传输给cpu

6 将组合解密为原文的过程叫解码。

9532 发表于 2023-8-1 15:12:15

666

bwwforever 发表于 2023-8-1 16:29:45

跟着小甲鱼学C

embition 发表于 2023-8-1 17:59:16

加油

ael2177 发表于 2023-8-1 18:42:49

学习

18060974840 发表于 2023-8-1 19:39:53

桌面
页: 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 [1924] 1925 1926 1927 1928 1929 1930 1931 1932 1933
查看完整版本: S1E2:第一个程序 | 课后测试题及答案