十七步 发表于 2020-10-25 15:15:10

6666666666666666666666

夏夜星空海 发表于 2020-10-25 15:34:37

{:5_95:}

chenghengumr 发表于 2020-10-25 15:49:58

强👍

1165091814 发表于 2020-10-25 15:54:05

答案

讨啄的白菜 发表于 2020-10-25 16:20:27


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

cuihanwen97 发表于 2020-10-25 16:35:30

看答案啊啊啊

Toho06 发表于 2020-10-25 16:52:09

好耶

Burton0703 发表于 2020-10-25 17:02:31

daan

tianyuan134 发表于 2020-10-25 17:47:24

来了

rookieone23 发表于 2020-10-25 18:05:20

电脑如何截图

柠檬爆破 发表于 2020-10-25 18:10:33

回复

阐裡鹤唳 发表于 2020-10-25 20:50:14

让我康康{:10_256:}

qian596ok 发表于 2020-10-25 21:17:05

{:5_90:}

沉下心来学习 发表于 2020-10-25 21:31:56

查看参考答案

aim120missile 发表于 2020-10-25 21:52:21

        感谢楼主无私奉献!

a2249297710 发表于 2020-10-25 22:02:13

谢谢大佬

一零八 发表于 2020-10-25 22:28:32

答案答案

yitaioxianyu 发表于 2020-10-25 22:37:36

1

dan474822611 发表于 2020-10-26 01:57:14

1

望谙 发表于 2020-10-26 09:09:47

1
页: 913 914 915 916 917 918 919 920 921 922 [923] 924 925 926 927 928 929 930 931 932
查看完整版本: S1E2:第一个程序 | 课后测试题及答案