言言小哭包 发表于 2024-5-14 19:30:01


#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <字符串.h>

#define 最大 256

长总计;

int countLines(const char *文件名);
void findAllCodes(const char *路径);
void findAllFiles(const char *path);

int countLines(const char *文件名)
{
文件 *fp;
int 计数 = 0;
int 温度;

if((fp = fopen (filename, "r")) == NULL)
                {
fprintf(stderr,"无法打开文件:%s\n",filename);
返回 0;                       
                }
               
而((temp = fgetc(fp)) != EOF)
                {
如果 (temp == '\n')
                                {
计数++;                                       
                                }
                        }
               
fclose(fp);

返回计数;                               
}

void findAllCodes(const char *path)
{
结构_finddata_t fa;
长手柄;
char thePath,target;

strcpy(路径,路径);
if((handle = _findfirst(strcat(thePath,"/*.c"),&fa)) != -1L)
                {

                        {
sprintf(target,"%s/%s",路径,fa.name);
总计 += countLines(target);
}while (_findnext(handle,&fa) == 0);                       
                }
               
_findclose(句柄);
}

void findALLDirs(const char *path)
{
结构_finddata_t fa;
长手柄;
char thePath[最大];

strcpy(路径,路径);
if((handle = _findfirst(strcat(thePath,"/*"),&fa)) == -1L)       
                {
fprintf(stderr,"路径%s是错误的!\n",path);
返回;                       
                }


                {
if(!strcmp(fa.name,".")||!strcmp(fa.name,".."))
继续;

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()
{
字符路径= ".";

printf("计算中...\n");

                findALLCodes(path);
                findALLDirs(path);
       
printf("目前你总共写了%ld行代码!\n\n",total);
                system("pause");
               
返回 0;                               
}

overjoy 发表于 2024-5-14 22:14:45

我来瞧瞧

我是语句 发表于 2024-5-15 11:54:17

1111

asd116438411 发表于 2024-5-15 13:47:27

qwq

ABEL251 发表于 2024-5-15 21:32:36

{:5_102:}

微风拂困我 发表于 2024-5-15 23:56:07

想看{:5_109:}

qjhzzz1 发表于 2024-5-16 16:55:34

{:5_90:}

Wal_ 发表于 2024-5-16 18:10:13

每天学习一点点

蒜爆泥鳅 发表于 2024-5-16 20:59:37

666

淡雨丶 发表于 2024-5-16 23:07:12

{:9_227:}

鱼在路上飞 发表于 2024-5-17 15:42:49

111

haimingsong 发表于 2024-5-17 16:09:38

1

HJW666 发表于 2024-5-17 17:38:19

答案

社会头子hyz 发表于 2024-5-17 23:53:54

{:5_102:}

471628391 发表于 2024-5-18 16:02:36

1

ZKBdx 发表于 2024-5-18 19:43:05

计算中&#129488;

逍遥游@ 发表于 2024-5-19 02:30:30

1

久遠寺有珠 发表于 2024-5-19 13:07:28

查看参考答案

shiliu-017 发表于 2024-5-19 15:28:17

嘿嘿{:5_109:}

123xiaoY 发表于 2024-5-19 18:17:14

1
页: 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 [2028] 2029 2030 2031 2032 2033 2034 2035 2036 2037
查看完整版本: S1E2:第一个程序 | 课后测试题及答案