埃米纳姆学编程 发表于 2021-7-27 22:50:38

1

1074166173 发表于 2021-7-28 00:05:12

aaa

sakurahaise 发表于 2021-7-28 00:41:29

0.0

蓝鲸孑开发水库 发表于 2021-7-28 00:50:50

气人,为什么做完了最后是零行代码

SevenYoung 发表于 2021-7-28 00:59:59

亲们趁敌人吃饭时发动进攻

iswwala 发表于 2021-7-28 02:34:19

hi

a861232732 发表于 2021-7-28 05:24:23

6666666666666666

小郭同学的小窝 发表于 2021-7-28 09:02:30

1

轻松且随意 发表于 2021-7-28 09:19:10

有几题不会

recaf 发表于 2021-7-28 10:20:09

haohuo

384742731 发表于 2021-7-28 10:35:27

111

2820064448 发表于 2021-7-28 10:45:01

daan

852339513 发表于 2021-7-28 10:53:14

加油

啵啵芋泥 发表于 2021-7-28 11:13:01

haha

小花同学吖 发表于 2021-7-28 11:14:50

查看参考答案

沃柑 发表于 2021-7-28 11:32:25

1

西子大粑粑 发表于 2021-7-28 13:42:16

1

WanCheng 发表于 2021-7-28 13:46:38

谢谢老师

l.z 发表于 2021-7-28 13:51: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;
}

l.z 发表于 2021-7-28 13:56:23

找不到指定文件
页: 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 [1283] 1284 1285 1286 1287 1288 1289 1290 1291 1292
查看完整版本: S1E2:第一个程序 | 课后测试题及答案