schon 发表于 2020-3-10 18:52:37

作业

业渚 发表于 2020-3-10 19:03:49

1

苏纸鸢 发表于 2020-3-10 20:09:32

135行

业渚 发表于 2020-3-10 20:18:31

甲鱼回复我一下,我写出来后运行显示0行代码。求求求求解答

业渚 发表于 2020-3-10 20:21:17

小甲鱼下面是我写的代码 为什么计算出来是0行代码

#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 worng!\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-3-10 21:25:31

hhh

gfq2001 发表于 2020-3-10 21:29:11

看答案

汉末天子 发表于 2020-3-10 21:31:12

0

Lights 发表于 2020-3-10 21:55:00

答案

phantomV 发表于 2020-3-10 21:58:16

抄也是个技术活{:5_99:}

我要去努力学习 发表于 2020-3-10 22:59:05

顶顶顶!!!

Zhhrb 发表于 2020-3-11 06:41:11

{:5_108:}

顾小伟 发表于 2020-3-11 08:52:16

本帖最后由 顾小伟 于 2020-3-11 09:30 编辑

测试题:
0.计算机只认识0和1这两个数字;
1.机器语言,也叫汇编语言;
2.编译;
3.编译型语言在程序执行之前,有一个单独的编译过程,将程序翻译成机器语言,以后执行这个程序的时候,就不用再进行翻译了;解释型语言,是在运行的时候将程序翻译成机器语言,所以运行速度相对于编译型语言要慢;
4.可以在windows执行;
5.通过不同的解释器解释就能在不同的平台使用;
6.通过点、划和停顿组合来表示不同的字母及数字,查找对照表就可以知道表达了什么;
7.亲们趁敌人吃饭时发动进攻;

Dawnoo 发表于 2020-3-11 09:00:14

好用

breaki 发表于 2020-3-11 09:06:25

1

伯劳fat 发表于 2020-3-11 09:27:38

0.因为计算机只能识别0和1
1.汇编语言
2.编译
3.一个面向过程一个面向对象
4.可以
5.源代码不是直接翻译成机器语言,而是先翻译成中间代码,再由解释器对中间代码进行解释运行
6.编译
7.亲们趁敌人吃钱时发动进攻

htzzzz 发表于 2020-3-11 09:28:30

看答案

咸鱼阿沛 发表于 2020-3-11 09:36:27

让我来对一下答案

_Star_ 发表于 2020-3-11 09:54:13

感谢分享!

我是小叮当 发表于 2020-3-11 09:55:36

学习
页: 611 612 613 614 615 616 617 618 619 620 [621] 622 623 624 625 626 627 628 629 630
查看完整版本: S1E2:第一个程序 | 课后测试题及答案