yan9hu1 发表于 2021-10-21 20:43:07

小甲鱼好厉害

橘子耶 发表于 2021-10-21 20:50:01

chakai

烧香的熊猫 发表于 2021-10-21 20:58:18

1

矮子幻想家 发表于 2021-10-21 21:39:57


#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,"/*.c"), &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)
                {
                                strintf(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;
}

xyjzs 发表于 2021-10-21 22:28:39

回复

hao7862336 发表于 2021-10-21 22:44:59

6行代码

kecr 发表于 2021-10-21 23:55:41

搞定

LI嬴政 发表于 2021-10-22 00:48:44

ok

狗苟荀 发表于 2021-10-22 08:40:13

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

马利奥吃奥利奥 发表于 2021-10-22 09:09:15

学习学习

qq81547565 发表于 2021-10-22 09:22:58

学习

5946946 发表于 2021-10-22 10:45:04

对着答案

从c开始surfing 发表于 2021-10-22 11:28:09

0.计算机只能读懂二进制
1.机器语言
2.编译
3.转换方式不同
4.能
5.翻译
6.编译
7.亲们趁敌人吃饭时发动进攻

MySunshine123 发表于 2021-10-22 14:14:19

我爱小甲鱼

快乐起来学c 发表于 2021-10-22 14:25:56

答案呢

大西瓜已被注册 发表于 2021-10-22 14:47:43

为什么照着写有bug还不知道怎么改{:5_104:}

千氘ulta 发表于 2021-10-22 15:14:27

qwq
比python难

小11哦 发表于 2021-10-22 15:27:58

0 只能识别机器码,需要转换语言
1 机器码
2 编译
3 前者效率高,是计算机底层的基础。后者能跨平台,方便
4 不能
5 像我们中英文互译,需要对表
6 懒得翻

小牛喝牛奶 发表于 2021-10-22 15:54:24

666

鱼C! 发表于 2021-10-22 18:01:41

有没有解出来的大神
页: 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 [1429] 1430 1431 1432 1433 1434 1435 1436 1437 1438
查看完整版本: S1E2:第一个程序 | 课后测试题及答案