Spear-- 发表于 2021-10-26 14:37:47

0

xixize 发表于 2021-10-26 15:05:20

终于找到队伍,开心

Newbie丶 发表于 2021-10-26 17:55:40

加油

408323750 发表于 2021-10-26 18:26:44

11

ycylhy 发表于 2021-10-26 18:37:52

答案!

跑步是一种时尚 发表于 2021-10-26 19:23:17

讲的很好

跑步是一种时尚 发表于 2021-10-26 19:24:56

讲的很好

sLDD 发表于 2021-10-26 19:31:42


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

zzxxcc553311 发表于 2021-10-26 19:53:39

{:5_109:}

cool-w 发表于 2021-10-26 21:06:38

1

miracle-99 发表于 2021-10-26 21:27:38

加油!

song666 发表于 2021-10-26 22:09:41

答案

执棋 发表于 2021-10-26 22:28:07

答案

qisiwhdqew 发表于 2021-10-26 23:30:42

1

大梦想家hhh 发表于 2021-10-26 23:41:08

答案

洛清烟 发表于 2021-10-27 03:11:21

牛!

测绘农民工 发表于 2021-10-27 09:55:25

1

leon1011 发表于 2021-10-27 11:11:36

selvaamazing 发表于 2021-10-27 16:01:41

1111111111

小厌 发表于 2021-10-27 16:43:17

1
页: 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 [1439] 1440 1441 1442 1443 1444 1445 1446 1447 1448
查看完整版本: S1E2:第一个程序 | 课后测试题及答案