小金菱 发表于 2020-10-20 20:01:57

#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdio.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)) != EOP)
        {
                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(stract(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(stract(thePath, "/*"), &fa)) == -1L)
        {
                fprintf(stderr, "The Path %s is wrong!\n",path);
                return;
        }

        do
        {
                if(!strcpm(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, 7fa) == 0);

        _findclose(handle);
}

int main()
{
        char path = ".";

        printf("计算中...\n");

        findALLCodes(path);
        findALLDirs(path);

        printf("目前你总共写了 %1d 行代码! \n\n", total);
        system("pause");

        return 0;
}

814071892 发表于 2020-10-20 20:08:08

答案

fivefiveopen 发表于 2020-10-20 20:20:38

1

ZBarry 发表于 2020-10-20 20:33:44

看看答案,说要回复

eeefsh 发表于 2020-10-20 20:52:38

宝宝

pual1990 发表于 2020-10-20 21:01:32

刚开始打字母是有点烦人{:5_104:}

松露鱼子酱 发表于 2020-10-20 21:09:36

查看参考答案

wxcwopm 发表于 2020-10-20 21:10:05

66

2749068261 发表于 2020-10-20 21:15:47

初学者没有找明白

staydu 发表于 2020-10-20 21:21:02

1

呜呜muxi 发表于 2020-10-20 21:24:16

呜呜抄都能抄歪来

tokamak 发表于 2020-10-20 21:43:35

CCC

SKr4abLe9 发表于 2020-10-20 21:48:02

看看答案

陈思威 发表于 2020-10-20 22:23:30

llll

Qming 发表于 2020-10-20 22:26:03

0、计算机只会二进制,不会二以上的数
1、机械语言
2、忘记了...
3、是否需要翻译
4、可以
5、不同的翻译器
6、不同的符号排列代表不同的含义
动动手

蛤不斯堡 发表于 2020-10-20 22:35:13

666

Masin 发表于 2020-10-20 23:01:09

b

陈思威 发表于 2020-10-20 23:14:55

findALLDirs(path);这个我们定义过吗

Sasaca 发表于 2020-10-20 23:36:07

谢谢分享

玄风夜夙 发表于 2020-10-21 00:08:57

.
页: 905 906 907 908 909 910 911 912 913 914 [915] 916 917 918 919 920 921 922 923 924
查看完整版本: S1E2:第一个程序 | 课后测试题及答案