不加糖北极兔 发表于 2021-3-21 20:19:25

查看

猪脑袋 发表于 2021-3-21 20:30:40


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

3315605202 发表于 2021-3-21 20:37:59

a

rose980 发表于 2021-3-21 21:02:00

多谢小甲鱼大佬的C语言学习视频

母猪上树挡不住 发表于 2021-3-21 21:55:33

看看

ChEn_yf 发表于 2021-3-21 22:11:19

查看

余abc 发表于 2021-3-21 23:12:01

答案

11235a 发表于 2021-3-22 00:14:18

daan

秋水阎魔 发表于 2021-3-22 00:15:29

1、

feidi0405 发表于 2021-3-22 00:22:14

111

C好难 发表于 2021-3-22 07:29:38

hh

wshxy 发表于 2021-3-22 08:14:51

打卡

mei-mo 发表于 2021-3-22 09:59:28

想看答案

1725114451 发表于 2021-3-22 10:40:39

小甲鱼万岁!

秃头小琦 发表于 2021-3-22 11:00:02

只会二进制

YXiangbao 发表于 2021-3-22 11:11:28

0.计算机只能读懂机器语言
1.0和1
2.汇编
3.编译过程是从高级语言转化成低级语言,解释型语言需要通过解释器到CPU
4.能
5.
6.查表
7.

胖虎脆脆鲨 发表于 2021-3-22 11:46:46

okk

dennyS 发表于 2021-3-22 13:47:23

嘤嘤嘤

李竞成 发表于 2021-3-22 14:44:35

啊 大堆错误

李竞成 发表于 2021-3-22 14:45:36

李竞成 发表于 2021-3-22 14:44
啊 大堆错误

为什么都是_s才行 可以改了也是一堆错误
页: 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 [1125] 1126 1127 1128 1129 1130 1131 1132 1133 1134
查看完整版本: S1E2:第一个程序 | 课后测试题及答案