xueshuai 发表于 2019-9-3 20:19:03

///

空城追dream 发表于 2019-9-3 21:49:06

你好,我刚学,我想知道课后作业程序从一开始就是这么编译的,如何到达count-lines

dongwenjie 发表于 2019-9-3 22:30:10

0.机器只能识别二进制0 1的代码
1.机器语言
2.编译
3.解释型语言需要解释器将语言进行翻译
4.能
5.使用解释器
6.使用符号组合来代表实际功能
7.QINMENCHENDiR

Mkai 发表于 2019-9-3 22:41:34

{:10_254:}

purplepp 发表于 2019-9-3 22:46:22


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

lou 发表于 2019-9-4 00:10:06

1

WITPEN白羽 发表于 2019-9-4 01:10:03

本帖最后由 WITPEN白羽 于 2019-9-4 01:11 编辑

$ gcc cs.c -o cs
cs.c: 在函数‘countLines’中:
cs.c:19: 错误:‘FTLF’未声明(在此函数内第一次使用)
cs.c:19: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
cs.c:19: 错误:所在的函数内也只报告一次。)
cs.c:19: 错误:‘fp’未声明(在此函数内第一次使用)
cs.c: 在函数‘findAllDirs’中:
cs.c:64: 错误:‘null’未声明(在此函数内第一次使用)
$


这事为什么啊,大佬 ,头文件我都写了啊没有少写

chenyaofei 发表于 2019-9-4 07:24:45

认真做题,积极学习

Jiawei.Lu 发表于 2019-9-4 10:28:13

test

再见少年 发表于 2019-9-4 11:37:08

加油,今天是第一天学习

小影子吖 发表于 2019-9-4 14:27:07

对答案

fdffdghe 发表于 2019-9-4 15:12:47

看一看答案

小鱼干爱猫 发表于 2019-9-4 15:15:40

学习了

小十六 发表于 2019-9-4 16:35:17

666666666666666

2194619986 发表于 2019-9-4 16:50:55

zzzzz159195 发表于 2019-9-4 17:43:44

zhichi

amovox 发表于 2019-9-4 18:36:41

想学习

黎影 发表于 2019-9-4 19:16:03

小甲鱼老师,我这些是什么错误呀?

Dezso 发表于 2019-9-4 19:45:39

666

d975421647 发表于 2019-9-4 20:09:01

{:5_108:}
页: 379 380 381 382 383 384 385 386 387 388 [389] 390 391 392 393 394 395 396 397 398
查看完整版本: S1E2:第一个程序 | 课后测试题及答案