kedeidi 发表于 2021-10-5 18:51:17

l

1815702237 发表于 2021-10-5 20:43:31

{:5_104:}

lcn 发表于 2021-10-5 20:52:53

huifu

2502781629 发表于 2021-10-5 21:46:14

1

XCJ. 发表于 2021-10-5 22:01:52

加油好好学习

Virfzx 发表于 2021-10-5 22:14:59

.

Nuke_Desert 发表于 2021-10-5 23:05:43

感谢

小蜡笔看大海 发表于 2021-10-5 23:17:31

我来了我来了

猪头仙君 发表于 2021-10-6 00:49:16

不会

白鹭霜华 发表于 2021-10-6 09:00:14

萌新报道

灵域黑猫 发表于 2021-10-6 09:16:10

鬼渐xue技术 发表于 2021-10-6 09:46:20

答案

田庄庄 发表于 2021-10-6 12:47:09

怎么查看哇小甲鱼老师

1552045046 发表于 2021-10-6 14:20:21

1

Shosren 发表于 2021-10-6 15:04:24


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

caicaism 发表于 2021-10-6 15:38:39

{:10_277:}

中鱼鱼 发表于 2021-10-6 16:07:04

S1E2:第一个程序 | 课后测试题及答案

15597 发表于 2021-10-6 16:20:39

1

onewxy 发表于 2021-10-6 16:42:57

112

TomoLentern 发表于 2021-10-6 18:02:11

开幕雷击,第一次纯手打代码就是“id returned 1 exit status”
麻了
页: 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 [1404] 1405 1406 1407 1408 1409 1410 1411 1412 1413
查看完整版本: S1E2:第一个程序 | 课后测试题及答案