池上桜 发表于 2022-8-27 21:45:14

。。。

04230423 发表于 2022-8-27 23:39:59

AA

muye11 发表于 2022-8-28 08:44:03

答案

Jiayou111 发表于 2022-8-28 10:26:16

yyds

..东 发表于 2022-8-28 12:07:41

我会阿瓦达索命 发表于 2022-8-28 12:49:32

{:10_334:}

葉湘伦 发表于 2022-8-28 14:34:43

{:5_102:}

武川庸 发表于 2022-8-28 15:58:37

"C:\Users\user\Desktop\IMG20220828155718.jpg"

kangaroo3000 发表于 2022-8-28 17:04:37

查看答案

张宝杰 发表于 2022-8-28 21:35:14

答案

wgh1320716615 发表于 2022-8-29 01:19:49

1

Inkblot 发表于 2022-8-29 09:01:50

6

苦苦的巧克力 发表于 2022-8-29 09:30:01

本帖最后由 苦苦的巧克力 于 2022-8-29 09:32 编辑

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

lovemyselftoo 发表于 2022-8-29 10:18:32

字符串那个地方报错

kkjjyy 发表于 2022-8-29 11:45:22

1

啊呸呸呸 发表于 2022-8-29 12:12:58

感谢!

zhangjinxuan 发表于 2022-8-29 12:51:08

回复

zhangjinxuan 发表于 2022-8-29 12:55:25

致命错误:direct.h:没有那个文件或目录
#include <direct.h>
                           ^
编译中断。{:10_266:}

zcca 发表于 2022-8-29 16:08:10

查看参考答案

heart030921 发表于 2022-8-29 16:20:45

0
页: 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 [1717] 1718 1719 1720 1721 1722 1723 1724 1725 1726
查看完整版本: S1E2:第一个程序 | 课后测试题及答案