个个个个 发表于 2020-2-27 20:16:52

统计当前目录及所有子目录下,C 语言源文件的代码总行数,为0!

XYcarpenter 发表于 2020-2-27 20:29:15

已完成第一课练习!

凌风飞 发表于 2020-2-27 20:31:32

1

二十四桥烟雨 发表于 2020-2-27 20:39:05

0. 计算机只能看懂2进制
1.机器语言
2.编译
3.编译型语言把源代码编译成机器语言,解释性语言将源代码转换成中间代码,再发送给解译器翻译给CPU执行
4.不可以吧。
5.
6.查表

小黑鱼8421 发表于 2020-2-27 20:50:34

初来乍到

会飞的鱼9596 发表于 2020-2-27 21:12:49

1

gggzgong 发表于 2020-2-27 21:28:47

{:5_102:}

吴哲聪 发表于 2020-2-27 21:30:02

0.因为计算机会有很多Bug出现
1.C语言
2.编译
3.解释型语言不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行。编译型语言直接编译成机器码
4.不可以
5.解释型语言不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行
6.查表
7.亲们趁敌人吃饭时发动进攻

小灬小程序员 发表于 2020-2-27 22:10:09

{:5_102:}

qq907456668 发表于 2020-2-27 22:50:29

感谢感谢

Maplex. 发表于 2020-2-27 23:05:58

学习打卡

雷利76 发表于 2020-2-28 00:03:29

0.计算机只认识0、1
1.机器语言
2.编译
3.编译型:直接输出cpu可执行代码;解释型:不能直接输出cpu可执行代码
4.能
5.中间码,需用平台的解释器解释后方可让cpu执行
6.查表
7.哈哈哈

ddd。com 发表于 2020-2-28 00:17:17


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

corgicorgi 发表于 2020-2-28 00:42:17

#include<io.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;
}

ha1212 发表于 2020-2-28 10:53:47

答案{:5_91:}

lujiajiaying 发表于 2020-2-28 11:02:24

想要看答案

puyayang 发表于 2020-2-28 11:28:18

只懂二进制

忘了

后者给电脑时要多一步翻译

不能

忘了

忘了

有关吃饭

精英猎妈人 发表于 2020-2-28 11:36:44

奥利给干了!

1092356700 发表于 2020-2-28 11:44:59

我要答案啊!!

hang1021 发表于 2020-2-28 12:41:14

查看答案
页: 585 586 587 588 589 590 591 592 593 594 [595] 596 597 598 599 600 601 602 603 604
查看完整版本: S1E2:第一个程序 | 课后测试题及答案