小鱼干爱猫 发表于 2019-9-4 15:15:40

学习了

小十六 发表于 2019-9-4 16:35:17

666666666666666

2194619986 发表于 2019-9-4 16:50:55

zzzzz159195 发表于 2019-9-4 17:43:44

zhichi

amovox 发表于 2019-9-4 18:36:41

想学习

黎影 发表于 2019-9-4 19:16:03

小甲鱼老师,我这些是什么错误呀?

Dezso 发表于 2019-9-4 19:45:39

666

d975421647 发表于 2019-9-4 20:09:01

{:5_108:}

千秋寒夏 发表于 2019-9-4 20:13:29

答案

给你煮了小鱼米 发表于 2019-9-4 20:30:42

看一看

zhuzhixian2019 发表于 2019-9-4 21:19:59

{:5_90:}

sijin_qu 发表于 2019-9-4 21:24:12

2194619986 发表于 2019-9-4 22:06:55


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

我着咋显示109行代码呀0.0

1159197611 发表于 2019-9-4 22:28:08

11

小小学徒。 发表于 2019-9-5 08:24:31

好好学习,感谢小甲鱼

SCoout 发表于 2019-9-5 10:18:33

daan

Crazyeye 发表于 2019-9-5 10:30:53

答案

wrhball 发表于 2019-9-5 11:22:24

康康答案

mercyking 发表于 2019-9-5 12:35:29

厉害

鱼cLjl 发表于 2019-9-5 13:01:41

参考答案
页: 378 379 380 381 382 383 384 385 386 387 [388] 389 390 391 392 393 394 395 396 397
查看完整版本: S1E2:第一个程序 | 课后测试题及答案