LYH001 发表于 2022-11-6 08:33:13

{:5_109:}

hairbro 发表于 2022-11-6 10:32:53

1

python_monkey 发表于 2022-11-6 13:32:19

查看参考答案

yukari123 发表于 2022-11-6 13:40:38

{:5_102:}

kbxs7 发表于 2022-11-6 13:51:39

{:5_102:}

摩羯座是大笨蛋 发表于 2022-11-6 15:00:05


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

inginging 发表于 2022-11-6 15:02:02

查看参考答案

lainl 发表于 2022-11-6 16:35:29

1

软件de苦行僧 发表于 2022-11-6 16:42:35

答案

千代子 发表于 2022-11-6 20:16:42

回复

1390903201 发表于 2022-11-6 21:13:25

看一眼

初梦无限 发表于 2022-11-6 22:13:27

我忘了

初梦无限 发表于 2022-11-6 22:17:15

初梦无限 发表于 2022-11-6 22:13
我忘了

"C:\Users\曾庆焜\Pictures\Screenshots\屏幕截图(23).png"

白手起家学C 发表于 2022-11-6 22:28:21

{:5_100:}惭愧偷看

揉尘 发表于 2022-11-7 09:19:47

1

Mecamodore 发表于 2022-11-7 10:12:30

写完啦来看答案!

小张子 发表于 2022-11-7 10:59:22

1

钟情于风 发表于 2022-11-7 11:16:29

答案是啥

lifuchang 发表于 2022-11-7 14:32:39

查看答案

所以无处容身 发表于 2022-11-7 15:43:32

只能识别机器语言
页: 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 [1795] 1796 1797 1798 1799 1800 1801 1802 1803 1804
查看完整版本: S1E2:第一个程序 | 课后测试题及答案