597392964 发表于 2022-10-13 07:53:00

1

597392964 发表于 2022-10-13 07:53:39

答案

长野 发表于 2022-10-13 09:11:45

学习!

5875 发表于 2022-10-13 10:06:23

1

jess7 发表于 2022-10-13 10:54:22

0

1600165855 发表于 2022-10-13 13:27:01

{:5_90:}

sususususu 发表于 2022-10-13 13:57:53


fishc666

航玥爱学习 发表于 2022-10-13 15:25:33

已完成

无幕想 发表于 2022-10-13 15:53:13

回复

zyyyl 发表于 2022-10-13 15:54:16


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

来自星星的夜空 发表于 2022-10-13 17:10:19

查答案来啦

RIkL 发表于 2022-10-13 18:56:25

{:10_243:}

程123456 发表于 2022-10-13 19:26:05

1

立功小子 发表于 2022-10-13 19:50:35

1111111111111111

不响丸辣w 发表于 2022-10-13 19:53:34

谢谢

fish2004 发表于 2022-10-13 20:17:39

我爱小甲鱼

fish2004 发表于 2022-10-13 20:18:14

6

李大只Li 发表于 2022-10-13 21:06:07

1

最紧要靓仔 发表于 2022-10-13 21:07:27

打卡

尧天舜帝 发表于 2022-10-13 21:19:51

111
页: 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 [1774] 1775 1776 1777 1778 1779 1780 1781 1782 1783
查看完整版本: S1E2:第一个程序 | 课后测试题及答案