GBIlIbIlI 发表于 2018-11-12 12:57:20

I love FishC.com!

lipo0 发表于 2018-11-12 15:41:56

想看看跟自己想的是不是一样

youxie 发表于 2018-11-12 15:59:06

验证

北峯 发表于 2018-11-12 16:22:22

本帖最后由 北峯 于 2018-11-12 16:31 编辑

{:10_265:}

顾西凉 发表于 2018-11-12 16:31:25

已经做完了。

顾西凉 发表于 2018-11-12 17:47:19

复制的代码还是有很多问题怎么解决我用的编译器是vs2017

timor180 发表于 2018-11-12 17:50:20

{:5_101:}{:5_101:}

874404627 发表于 2018-11-12 19:26:32

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

被遗弃的咸鱼干 发表于 2018-11-12 20:36:11

看答案嘿嘿嘿

zaq7434 发表于 2018-11-13 10:26:11

看答案啦

歪脖子大侠 发表于 2018-11-13 13:32:57

{:5_90:}{:5_109:}

binance 发表于 2018-11-13 16:02:16

{:5_103:}

艮山 发表于 2018-11-13 16:58:24

支持版主

1113727163 发表于 2018-11-14 10:47:00

看答案

Nekroz 发表于 2018-11-14 10:52:00

新人学习!!

小饼干丷 发表于 2018-11-14 10:53:58

6666666666666666666666

wjc2025 发表于 2018-11-14 11:06:59

嘿,亲爱的鱼油,每天都要过得开心哦

简艺5020 发表于 2018-11-14 15:09:20

我爱鱼C

我爱学c语言 发表于 2018-11-14 15:10:16

111

爪子z 发表于 2018-11-14 17:16:00

学习...
页: 195 196 197 198 199 200 201 202 203 204 [205] 206 207 208 209 210 211 212 213 214
查看完整版本: S1E2:第一个程序 | 课后测试题及答案