张三ccccccc 发表于 2024-8-29 09:44:59

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com

kaumpeb33 发表于 2024-8-29 10:47:57

计算中...
目前你总共写了 104 行代码!

Re.shortime 发表于 2024-8-29 11:40:10

已完成

淋雪共白头 发表于 2024-8-29 12:05:24

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

#define MAX         256

long total;

int countLines(const char* filename);
void findALLCodes(const char* patch);
void findALLFiles(const char* patch);

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_s(thePath, path);
        if ((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
        {
      do
                {
                        sprintf_s(target, "%s/%s", path, fa.name);
                        total += countLines(target);
                } while (_findnext(handle, &fa) == 0);
        }

        _findclose(handle);
}

void findALLFiles(const char* patch)
{
}

void findALLDirs(const char* path)
{

        struct _finddata_t fa;
        long handle;
        char thePath;

        sprintf_s(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_s(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("目前你总共写了 %1d 行代码! \n\n", total);
        system("pause");

        return 0;
}
up好,我照着你的这个输入后检查无误但是它提示我fopen和strcat存在危险,在代码第一行输入#define_CRT_SECURE_NO_WARINGS后依然有报错,想问一下这是怎么回事

韩爱玩王者 发表于 2024-8-29 15:46:18

1

CROCODILEzj 发表于 2024-8-29 19:45:29

{:5_105:}

寻找自由的鱼 发表于 2024-8-29 22:22:48

查看参考答案

yuanzhenxun 发表于 2024-8-29 23:16:40


yuanzhenxun 发表于 2024-8-30 07:17:28

.

xiaoyangzhu 发表于 2024-8-30 11:01:10

C:\Users\GH\Pictures\1.jpg
打印出来乱码了

吧啦嘛腻哄 发表于 2024-8-30 16:09:46

赞同

studyWK 发表于 2024-8-31 15:27:22

1

认真就会输樂 发表于 2024-8-31 16:28:52

{:5_108:}

认真就会输樂 发表于 2024-8-31 16:30:23

我觉得这是很不错的,哈哈

后会无期@77 发表于 2024-8-31 20:29:05

1

姜江江 发表于 2024-8-31 22:58:50

鱼C有你更精彩^_^

wwwwudi 发表于 2024-9-1 18:04:43

1

河涧渡 发表于 2024-9-2 14:22:59

0:CPU是计算机的大脑,虽然它很快,但它并不聪明,它只懂得二进制的-0和1 ,所以如果直接对它下命令,那就是在对牛弹琴,
1:第一代语言,编程语言。
2:编译。引入了大量的助记符来帮助人民编程,然后由汇编编译器将这些助记符转换为机器语言,这个转化的过程称为编译。
3:解释型语言不直接编译成机器语言,而是将源代码转换成中间代码,然后发给解释器,由解释器逐句翻译给CPU来执行。这样好处是可以实现跨平台的功能,缺点结束效率相对要低一些,因为每执行一次都要翻译一次。
4:可以。可移植性高是指源代码不需要做改动或只需稍加改动,就能够在其他机器上编译后正确运行。
5:解释型语言不直接编译成机器语言,而是将源代码转换成中间代码,然后发给解释器,由解释器逐句翻译给CPU来执行。这样好处是可以实现跨平台的功能,缺点结束效率相对要低一些,因为每执行一次都要翻译一次。
6: 查表。
7:不知道(悲)

Mineralie 发表于 2024-9-2 14:32:06

1

关关海 发表于 2024-9-2 20:14:24

查看答案
页: 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 [2051] 2052 2053 2054 2055 2056 2057 2058 2059 2060
查看完整版本: S1E2:第一个程序 | 课后测试题及答案