XTY丶Gu 发表于 2020-1-17 16:28:30

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

129784626 发表于 2020-1-17 17:11:58

1

BobDylan 发表于 2020-1-17 17:47:48

查看参考答案

张ks 发表于 2020-1-17 18:06:23

学c第一天

CCCfeichangshua 发表于 2020-1-17 18:57:15

感谢感谢

水山云烟 发表于 2020-1-17 19:00:59

目前你写了855行代码

beiyue 发表于 2020-1-17 19:05:56

muji

pwh445322 发表于 2020-1-17 19:07:39

zz

hehe1234 发表于 2020-1-17 19:38:31

1

吆不到台 发表于 2020-1-17 19:53:16

1.机器码
2.编译
3.直接与间接
4.能
5.字节码发送到解释器
6.编码与解码
7.亲们趁敌人吃饭时发动进攻。

knightmares 发表于 2020-1-17 20:19:43

6666

xianyu乙 发表于 2020-1-17 20:21:25

答案

LILILPLP 发表于 2020-1-17 20:22:00

1

起名不能 发表于 2020-1-17 20:52:19

WANDS123 发表于 2020-1-17 21:35:20

还行

大桔子 发表于 2020-1-17 21:40:33

小甲鱼{:5_108:}

McCollum 发表于 2020-1-17 22:29:25

1

谪仙?! 发表于 2020-1-17 23:19:18

小甲鱼程序第27行错了是咋回事啊

DLC-ppp 发表于 2020-1-17 23:31:26

学习c语言的第一天。

国子祭酒 发表于 2020-1-17 23:35:01

daan
页: 510 511 512 513 514 515 516 517 518 519 [520] 521 522 523 524 525 526 527 528 529
查看完整版本: S1E2:第一个程序 | 课后测试题及答案