ckw666 发表于 2021-10-11 15:13:10

1

zhoushiqian 发表于 2021-10-11 15:20:29

回复

Philbert 发表于 2021-10-11 15:37:33

1

南宫北沫 发表于 2021-10-11 17:14:43

今天开始学,希望在这一方面学的更好

说好不放手 发表于 2021-10-11 17:35:15

查看参考答案

1377270709 发表于 2021-10-11 17:51:51

???

bbbbbn 发表于 2021-10-11 19:07:39

{:10_254:}

poiqwe 发表于 2021-10-11 19:30:55

AlvinYe 发表于 2021-10-11 19:37:13

答案

zjjyyds 发表于 2021-10-11 20:03:51

as2998919571 发表于 2021-10-11 20:08:04

感谢分享

夹心包子 发表于 2021-10-11 20:41:02

做完了,怎么交作业

小甲鱼可以放生? 发表于 2021-10-11 20:46:18


#include<io.h>
#include<direct.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX    256

long total;

int countLine(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;
}

小甲鱼可以放生? 发表于 2021-10-11 20:47:05

小甲鱼可以放生? 发表于 2021-10-11 20:46
#include
#include
#include


为什么最后显示出来是0行代码?求答,鱼叔

hhhhhkkk 发表于 2021-10-11 20:52:01

1

LMT666 发表于 2021-10-11 21:11:08

1

ccl010828 发表于 2021-10-11 21:24:26

qinmenchendirenchifanshifadongjingong

liuhaolan1997 发表于 2021-10-11 21:44:06

看答案

编程yyds 发表于 2021-10-11 21:50:34

1

小怪爱学习 发表于 2021-10-11 22:19:45

include
页: 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 [1413] 1414 1415 1416 1417 1418 1419 1420 1421 1422
查看完整版本: S1E2:第一个程序 | 课后测试题及答案