国际铁憨憨 发表于 2019-12-7 11:07:36

daan

丑戌三 发表于 2019-12-7 12:38:01

复制代码运行显示的是目前您总共写了204行代码,
我自己全部照着打一遍运行的程序在不断循环跑动。。。时不时显示我桌面文件夹的名字,后面还有is wrong...

Viictor 发表于 2019-12-7 13:17:11


#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("目前你总共写了%1d行代码!\n\n",total);
        system("pause");
        return 0;
}

在下托尼老师 发表于 2019-12-7 14:08:58

.

Dylan_ 发表于 2019-12-7 14:51:43

感谢分享

是畇紹哦 发表于 2019-12-7 15:31:59

-

zheyuGG 发表于 2019-12-7 15:51:57

看看

片刻降临 发表于 2019-12-7 17:14:16

来吧

CarlosX 发表于 2019-12-7 17:15:44

wx930401 发表于 2019-12-7 18:15:45

莫斯代码查起来好像蛮麻烦

wx930401 发表于 2019-12-7 19:12:17

wx930401 发表于 2019-12-7 18:15
莫斯代码查起来好像蛮麻烦

我运行出了111行

dayuwan 发表于 2019-12-7 19:42:52

{:9_241:}

AuroraJ 发表于 2019-12-7 20:52:41

422让穷人啊发发而且其他团体的刚刚

a840204992 发表于 2019-12-7 21:20:10

做完了,看看答案

枫以如斯 发表于 2019-12-7 21:21:46

烦烦烦

Eisenheim 发表于 2019-12-7 21:47:33

我好了

carzydean 发表于 2019-12-7 22:33:28

kankab

无痕Djun 发表于 2019-12-8 00:07:56

看看

91李先生 发表于 2019-12-8 06:19:46

wph521521 发表于 2019-12-8 13:24:04

看看
页: 472 473 474 475 476 477 478 479 480 481 [482] 483 484 485 486 487 488 489 490 491
查看完整版本: S1E2:第一个程序 | 课后测试题及答案