z090012 发表于 2021-7-2 14:18:42

11

unicellular 发表于 2021-7-2 14:44:40

答案

超超爱学习 发表于 2021-7-2 14:47:51

11

skyren 发表于 2021-7-2 14:53:46

meidana

池芮132218 发表于 2021-7-2 15:38:04


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

杯酒盏茶 发表于 2021-7-2 15:43:00

.

杯酒盏茶 发表于 2021-7-2 16:07:48

我就是复制了代码放在vs2019上都运行不了,为啥?

kmeb9 发表于 2021-7-2 17:26:21

111111

Smallblack675 发表于 2021-7-2 17:47:46

完了

willian 发表于 2021-7-2 17:54:33

1

onionrain 发表于 2021-7-2 18:21:35

楼主辛苦

汤函 发表于 2021-7-2 19:05:41

.

came 发表于 2021-7-2 20:52:12

要看

came 发表于 2021-7-2 21:00:33

onionrain 发表于 2021-7-2 21:58:27

为啥我写完是目前您已写了0行代码,哭了

懵逼的小胖墩 发表于 2021-7-2 23:18:05

二进制0和1      机器语言      编译   能否实现跨平台特性   能       依照铭文一一对应解密为原文                                                解释器逐句翻译
亲们趁敌人吃饭时发动进攻

Ethn 发表于 2021-7-3 00:15:37

为什么我window系统打出来显示的是109行代码 左边的行数最多102行

炎黔 发表于 2021-7-3 07:45:24

敲完一边windows的之后安了个虚拟机加Linux,现在再敲Linux的{:9_227:}

小鱼2021 发表于 2021-7-3 09:24:36

加油干

小鱼2021 发表于 2021-7-3 10:24:22

小鱼2021 发表于 2021-7-3 09:24
加油干

打卡第一天
页: 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 [1233] 1234 1235 1236 1237 1238 1239 1240 1241 1242
查看完整版本: S1E2:第一个程序 | 课后测试题及答案