王大平 发表于 2022-1-20 17:35:37

报道

小徐一步一步。 发表于 2022-1-20 17:42:04

....

LIYIER 发表于 2022-1-20 18:18:29


#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, ".") || !strcpy(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;
}

L1ght 发表于 2022-1-20 19:18:30

111

@187 发表于 2022-1-20 19:39:30

上面的是Windows的
下面的是Linux 和 MacOS的吧!

二胡不口胡 发表于 2022-1-20 19:40:56

DAAN

明来 发表于 2022-1-20 20:16:50

1

skatding 发表于 2022-1-20 20:21:17

ok

Cannian001 发表于 2022-1-20 20:59:41

回复

baweihao 发表于 2022-1-20 21:04:14

1111111111

我想赚钱 发表于 2022-1-20 21:12:53

1

哈哈la 发表于 2022-1-20 22:18:50

1

2898083617 发表于 2022-1-20 22:18:50

.

柯菜人 发表于 2022-1-20 22:19:31

终于打完了,虽然还是错了编译不出来
{:5_104:}继续加油

我是大大怪123 发表于 2022-1-20 22:22:16

为啥

柯菜人 发表于 2022-1-20 22:29:54

全部代码打完了,虽然中间还是有错误,导致编译的时候编译不出来
这代表我心不够细,继续努力加油{:10_256:}

Διογνη 发表于 2022-1-20 23:14:07

S1E2

AmisfSH 发表于 2022-1-20 23:22:19

瞅瞅

不会C也不会飞 发表于 2022-1-21 10:17:02

答案是什么捏

deer_7 发表于 2022-1-21 10:24:50

第一天打卡。
代码敲的还是累
页: 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 [1533] 1534 1535 1536 1537 1538 1539 1540 1541 1542
查看完整版本: S1E2:第一个程序 | 课后测试题及答案