无梦三更 发表于 2020-2-9 21:12:14

无法编译

尘遥929 发表于 2020-2-9 21:14:32

..

书染 发表于 2020-2-9 21:22:44

嗯嗯

Caring 发表于 2020-2-9 21:58:42

错了好多

DTY123 发表于 2020-2-9 22:40:32

666

wangyulu0451 发表于 2020-2-10 00:44:03

回复见答案

aaahe 发表于 2020-2-10 00:49:56

111111111111111111

liuy1 发表于 2020-2-10 10:17:45

1

liuy1 发表于 2020-2-10 10:18:32

1

hangout 发表于 2020-2-10 10:49:12

感谢分享

客人1326 发表于 2020-2-10 11:02:12

0:

mcwtybz 发表于 2020-2-10 11:42:00


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

TK丿云游四海 发表于 2020-2-10 11:51:07

本帖最后由 TK丿云游四海 于 2020-2-10 11:57 编辑

手敲代码一次成功!

小黄人666 发表于 2020-2-10 11:53:42

{:10_249:}

不吃香菜的海带 发表于 2020-2-10 11:55:39

就看见空间

271428293 发表于 2020-2-10 12:15:39

1

极速飞客 发表于 2020-2-10 13:36:42

大牙

licuna 发表于 2020-2-10 13:39:10

感谢楼主无私奉献!

Jackcoc 发表于 2020-2-10 13:42:57

ncie

小刘冲冲冲 发表于 2020-2-10 13:44:25

嘻嘻   我想知道哇测试题的答案
页: 547 548 549 550 551 552 553 554 555 556 [557] 558 559 560 561 562 563 564 565 566
查看完整版本: S1E2:第一个程序 | 课后测试题及答案