HT道长 发表于 2019-6-4 16:28:56

抄代码都能错{:10_266:}{:10_266:}

新人头铁怪 发表于 2019-6-4 16:33:54

{:10_245:}{:10_258:}{:10_281:}{:10_254:}{:10_279:}目标撸10w行代码,冲冲冲!

求生者 发表于 2019-6-4 17:37:26

看一下

不见昙华盛 发表于 2019-6-4 18:13:44

打完了,但是..........

lfd2019 发表于 2019-6-4 18:35:07

自学加油

kecho 发表于 2019-6-4 18:49:58

学习

wslyq 发表于 2019-6-4 20:18:11

苏小拉 发表于 2019-6-5 07:27:07

谢谢鱼c老铁

小雨无语 发表于 2019-6-5 09:31:54


Aoser 发表于 2019-6-5 11:41:01

hello world

denghonggui 发表于 2019-6-5 12:30:20

mark

JFeng 发表于 2019-6-5 14:18:21

{:5_102:}

lsheihei 发表于 2019-6-5 14:26:12

谢谢分享!

cage233 发表于 2019-6-5 15:09:10

1.只认识0和1
2.机器语言
3.编译
4.能
5.
6.

a442127830 发表于 2019-6-5 16:17:16

看看答案 学习一下

Milier 发表于 2019-6-5 17:53:22

为啥运行结果是11
{:5_99:}
#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 findALLFile(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("目前你总共写了%2d行代码!\n\n",total);
        system("pause");

        return 0;
}

tianjudie 发表于 2019-6-5 22:47:57

QINMENCHENDIRENGHIFANSHIFADONGJINGONG

453022113 发表于 2019-6-6 01:07:45

加油

newnhoj 发表于 2019-6-6 01:07:56

finished it yet

xin... 发表于 2019-6-6 02:40:33

{:5_90:}
页: 298 299 300 301 302 303 304 305 306 307 [308] 309 310 311 312 313 314 315 316 317
查看完整版本: S1E2:第一个程序 | 课后测试题及答案