千秋寒夏 发表于 2019-9-4 20:13:29

答案

给你煮了小鱼米 发表于 2019-9-4 20:30:42

看一看

zhuzhixian2019 发表于 2019-9-4 21:19:59

{:5_90:}

sijin_qu 发表于 2019-9-4 21:24:12

2194619986 发表于 2019-9-4 22:06:55


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

我着咋显示109行代码呀0.0

1159197611 发表于 2019-9-4 22:28:08

11

小小学徒。 发表于 2019-9-5 08:24:31

好好学习,感谢小甲鱼

SCoout 发表于 2019-9-5 10:18:33

daan

Crazyeye 发表于 2019-9-5 10:30:53

答案

wrhball 发表于 2019-9-5 11:22:24

康康答案

mercyking 发表于 2019-9-5 12:35:29

厉害

鱼cLjl 发表于 2019-9-5 13:01:41

参考答案

可以学但没必要. 发表于 2019-9-5 15:37:04

1

库里学渣昂 发表于 2019-9-5 16:02:33

daan

一只小白猪 发表于 2019-9-5 16:07:33

{:5_109:}

肥熊仙人 发表于 2019-9-5 16:54:21

干货多多

1303048037 发表于 2019-9-5 19:28:15

0.计算机智能识别机器语言
1.机器语言
2.编译
3.否
4.可以
5.通过翻译器
6.明码对应

pzjnew 发表于 2019-9-5 20:35:22

0.1

强仔带你飞 发表于 2019-9-5 21:16:18

看看答案

WX2324 发表于 2019-9-5 21:32:25

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