影山结衣 发表于 2020-12-5 23:04:24

回复

Smile6 发表于 2020-12-5 23:15:52

感谢分享

翰林苏学士 发表于 2020-12-5 23:37:42

答案

Lwt666 发表于 2020-12-6 01:23:31

好的

dududu_fishc 发表于 2020-12-6 03:03:01

查看参考答案

软妹萌萌哒 发表于 2020-12-6 12:18:33

谢谢小甲鱼

永铜路小佩奇 发表于 2020-12-6 13:14:44

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

#define MAX   256

long totoal;

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)
        {fprint(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)
        {
                fprint(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;
}

编译时软件说我total未声明,再看一眼又是头文件<io.h>不认识,请问这是个什么情况

永铜路小佩奇 发表于 2020-12-6 14:11:30

那个程序一个一个字母的纠错完了,所以我已经搞定了,麻烦了

电竞少女 发表于 2020-12-6 15:54:54

111

小徐真的不会秃 发表于 2020-12-6 16:48:08

坚持第一天!

Dai. 发表于 2020-12-6 17:31:12

.不会哎

88412280 发表于 2020-12-6 18:19:29

1

炸药小碉堡 发表于 2020-12-6 18:36:12

1

2957865150 发表于 2020-12-6 21:58:27

答案

qq843225357 发表于 2020-12-6 22:12:37

111

m496447738 发表于 2020-12-6 23:55:25

学习记录

2294185301 发表于 2020-12-7 11:09:53

1

Kanata1127 发表于 2020-12-7 12:18:05

QAQ

surprise1su 发表于 2020-12-7 16:19:00

查看答案!!

ycbrisk 发表于 2020-12-7 16:49:20

日常打卡之第一天!学习中
页: 963 964 965 966 967 968 969 970 971 972 [973] 974 975 976 977 978 979 980 981 982
查看完整版本: S1E2:第一个程序 | 课后测试题及答案