c语言弱子 发表于 2022-9-14 15:06:56

为什么我是一堆亲戚怪怪的东西

cjj112233 发表于 2022-9-14 15:31:01

1

柯教授 发表于 2022-9-14 15:32:09

已完成

chencc0424 发表于 2022-9-14 15:51:59

9.14

woaihuangshiyu 发表于 2022-9-14 15:54:48

答案

17324713809 发表于 2022-9-14 15:55:54

查看答案

55564454 发表于 2022-9-14 16:22:30

666

arouse233 发表于 2022-9-14 17:36:45

查看参考答案

bsbbssbs 发表于 2022-9-14 18:36:15

二进制
01
编译


dlmhsh 发表于 2022-9-14 19:06:39

想知道答案

2019212542 发表于 2022-9-14 19:16:11

真难啊

衣槐雪 发表于 2022-9-14 19:30:46

{:5_109:}

我真服你个老六 发表于 2022-9-14 19:54:40

6

苍蓝星. 发表于 2022-9-14 19:56:06

答案

i1548708011 发表于 2022-9-14 20:00:00

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

Quinn328888 发表于 2022-9-14 20:06:57

6

1806578707 发表于 2022-9-14 20:27:39

{:5_90:}

Ping_Zi 发表于 2022-9-14 20:35:23

dafa

nalanlyk 发表于 2022-9-14 20:39:12


朱雀院红叶 发表于 2022-9-14 21:09:56

本帖最后由 朱雀院红叶 于 2022-9-14 21:40 编辑

png上传不了啊
页: 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 [1742] 1743 1744 1745 1746 1747 1748 1749 1750 1751
查看完整版本: S1E2:第一个程序 | 课后测试题及答案