moonfangfei 发表于 2022-9-3 21:15:18

1

heshaowen 发表于 2022-9-3 21:15:59

一只猴 发表于 2022-9-3 22:07:32

查看参考答案

wszzjdsg 发表于 2022-9-3 22:14:10

第一次

CCFCSQT 发表于 2022-9-3 22:30:04

查看答案

@@ConneR 发表于 2022-9-3 22:35:17

救命运行不了vs可能缺点啥

宝宝不孤单 发表于 2022-9-3 22:42:26

.

czyan 发表于 2022-9-3 22:45:07


#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;
}

2945842744 发表于 2022-9-4 08:19:13

0.只认识二进制
1.机器语言
2.编译
3

朔风s 发表于 2022-9-4 08:59:09

。。。。。

Ericlove 发表于 2022-9-4 10:22:46

1

annnnnnnnnovice 发表于 2022-9-4 10:48:21

芝麻开门

小黑子101010 发表于 2022-9-4 15:20:27

1

greastpeace 发表于 2022-9-4 15:23:42

666

清如许 发表于 2022-9-4 16:05:26

102

八戒的梨涡 发表于 2022-9-4 16:50:59

感谢分享

a123. 发表于 2022-9-4 16:55:05

1

1325008662 发表于 2022-9-4 17:37:13

小甲鱼yyds!

Alex尘风 发表于 2022-9-4 17:56:40

答案

半条咸鱼 发表于 2022-9-4 18:26:10

打卡2333
页: 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 [1728] 1729 1730 1731 1732 1733 1734 1735 1736 1737
查看完整版本: S1E2:第一个程序 | 课后测试题及答案