黎明§末日 发表于 2024-3-25 17:18:35

本帖最后由 黎明§末日 于 2024-3-25 17:21 编辑

课后作业:
测试题:
0:cpu它只能读的懂2进制的0和1
1:机器语言
2:编译
3:编译型语言编译出来的机器语言是可执行文件,可以直接被cpu执行
解释型语言不直接编译成机器码,而是将源代码转化为中间代码,发送给解释器由解释器逐句翻译给cpu执行
4:不能
5:解释器可以把源码编译成不同平台的代码,从而实现跨平台
6:是查表
7:qin men chen di ren chi fan shi fa dong
亲们 趁敌人吃饭时发动
动动手:

#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;
}

Arrow91372468 发表于 2024-3-25 17:22:28

学习学习

admian 发表于 2024-3-25 21:01:46

完成

2652259867 发表于 2024-3-25 22:29:11

查看参考答案

R0se 发表于 2024-3-25 23:08:01

加油!

丁威雲 发表于 2024-3-26 10:01:04

.

evi__ 发表于 2024-3-26 11:08:50

学习!

爱意寄给海底 发表于 2024-3-26 12:54:00

{:5_104:}

fengzhiwei 发表于 2024-3-26 14:41:57

111

辞风 发表于 2024-3-26 16:08:05

抄完了,执行不了一点,把原代码复制过去和自己敲的错误数一样,不知道咋解决

请给我一朵花 发表于 2024-3-26 18:26:51

我来啦

繁华灬入梦 发表于 2024-3-26 18:47:17

0:难道说因为是二进制的原因?
1:汇编语言
2:编译
3:一个是全部编写完再编译,一个是可以随时添加?
4:可以
5:因为他是转换成字节码,再有解释器翻译
6:二进制,0和1组成的代码
7:qfnmen chend irenc hifan shif adong jingo ng(猜不出来{:10_266:})

霜降yyk 发表于 2024-3-26 20:59:49

6

hjghjg 发表于 2024-3-26 21:13:56

想看答案

hjghjg 发表于 2024-3-26 21:22:14

啊,为什么我抄完但结果是0行(Linux)

遖頔 发表于 2024-3-26 21:25:56


#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;
}

Ginayi 发表于 2024-3-27 13:14:33

0

浅塘半亩 发表于 2024-3-27 13:16:52

1

3142325821 发表于 2024-3-27 14:19:20

1

晓风丿灬残月 发表于 2024-3-27 15:47:41

{:9_227:}
页: 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 [2023] 2024 2025 2026 2027 2028 2029 2030 2031 2032
查看完整版本: S1E2:第一个程序 | 课后测试题及答案