伍六七. 发表于 2020-2-19 14:17:59

{:9_241:}

jszqf 发表于 2020-2-19 14:53:18

谢谢分享

dkyml 发表于 2020-2-19 15:13:59

111

人如其名 发表于 2020-2-19 15:45:58

d哈哈

hyppp 发表于 2020-2-19 16:12:12

{:5_109:}

嗐嗐 发表于 2020-2-19 16:29:31

{:5_106:}

叶子菲菲 发表于 2020-2-19 16:33:33

亲们 趁敌人吃饭时发动进攻

dafantong 发表于 2020-2-19 16:48:21

课后题有点难啊

PhilCLee 发表于 2020-2-19 16:58:48

不知道啥意思啊

Mxyyy 发表于 2020-2-19 17:04:41

0.计算机只能识别0,1
1.机器语言
2.编译
3.编译型语言需要通过编译变为机器语言,解释型语言需要解释器来让CPU识别
4.可以,C语言具有可移植性
5.
6.一一映射
7.亲们趁敌人吃饭时发动进攻

大大大大大白 发表于 2020-2-19 17:08:41


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

白衣如旧 发表于 2020-2-19 17:51:03

查看参考答案

YANGLJ9733 发表于 2020-2-19 20:07:35

查看答案

icekurim 发表于 2020-2-19 20:15:25

查看参考答案

王莓莓 发表于 2020-2-19 20:22:36

打完了

日出东海满穹星 发表于 2020-2-19 20:41:29

1

喵口33 发表于 2020-2-19 21:19:56

666

zj132128 发表于 2020-2-19 21:24:38

厉害哦

wagcsj 发表于 2020-2-19 21:35:13

hello啊

YancyHao 发表于 2020-2-19 21:35:45

努力学习第一天
页: 568 569 570 571 572 573 574 575 576 577 [578] 579 580 581 582 583 584 585 586 587
查看完整版本: S1E2:第一个程序 | 课后测试题及答案