黻黻之章 发表于 2020-9-13 13:49:39

查看参考答案

Ren_rf 发表于 2020-9-13 14:14:55

支持

良木 发表于 2020-9-13 14:31:46

6666

王企鹅号 发表于 2020-9-13 14:58:14

感谢楼主无私奉献!

相光光 发表于 2020-9-13 15:10:09

爱你

cl66666613 发表于 2020-9-13 15:14:20

我要看答案

黄黄黄黄大仙 发表于 2020-9-13 15:29:15

1111

Stitch丶 发表于 2020-9-13 15:44:32

mark 第一天

月光兔 发表于 2020-9-13 15:54:58

感谢楼主无私奉献

386181641 发表于 2020-9-13 16:03:00

第一个程序

高冷大猛男 发表于 2020-9-13 16:58:45

想看答案

pyylearn 发表于 2020-9-13 17:12:07

呃呃呃小白很难受

mty010704zly 发表于 2020-9-13 17:16:36

朕要查看

WQ0329 发表于 2020-9-13 17:17:06

感谢楼主无私奉献

弗拉明戈. 发表于 2020-9-13 17:54:16

查看参考答案

星河不可及 发表于 2020-9-13 20:11:37

对对答案

lll啦啦啦 发表于 2020-9-13 20:13:43


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

赴山鬼约 发表于 2020-9-13 20:14:24

大一报道!

泊云啊 发表于 2020-9-13 20:31:28

000

杵臼 发表于 2020-9-13 21:26:22

看看答案
页: 840 841 842 843 844 845 846 847 848 849 [850] 851 852 853 854 855 856 857 858 859
查看完整版本: S1E2:第一个程序 | 课后测试题及答案