大lili 发表于 2021-1-6 19:35:56

怎么输出零呢

vagus 发表于 2021-1-6 19:36:06

{:10_279:}

泽瑞达 发表于 2021-1-6 19:41:16

2197462750 发表于 2021-1-6 20:05: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("目前你总共写了 %1d 行代码! \n\n", total);
        system("pause");
       
        return 0;
}

KK的账号 发表于 2021-1-6 20:28:54

答案

cjlxcross 发表于 2021-1-6 20:44:28

111

Vision_ 发表于 2021-1-6 20:54:32

查看参考答案

jimmy1123 发表于 2021-1-6 21:16:09

看看

門先生 发表于 2021-1-6 21:48:06

1

雷大大666 发表于 2021-1-7 00:09:19

1111111

深海霸主皮皮虾 发表于 2021-1-7 08:07:13

就只是想看看答案

咕Gu娃Wa 发表于 2021-1-7 09:59:12

答案

Aiden777 发表于 2021-1-7 10:24:51

1

BlackMonkey 发表于 2021-1-7 10:45:10

成功运行

界王神04 发表于 2021-1-7 11:21:36

buzhidao

三分z699 发表于 2021-1-7 11:36:40

1、二进制的机器码
2、反汇编
3、计算机不能直接理解高级语言,只能直接理解机器语言,所以必须要把高级语言翻译成机器语言
4、可以
5、首先,其实说编译型语言不能跨平台其实不准确或者就是错误理解。其实编译型语言比如c语言也是跨平台语言,理论上,在不同平台装上对应的编译器就可以实现跨平台。但是编译型语言虽然是高级语言,却与平台联系比较紧密(操作系统都是用编译型语言编写的),因此针对不同平台(操作系统)可能有其特定的编写
6、最早的摩斯密码是一些表示数字的点和划线数字,后来通过点、划、中间的停顿来把字元和标点符号分别发送出去
7、F:\A下载安装包\小甲鱼\作业\第一次作业

go-wxl 发表于 2021-1-7 11:37:54

需要答案

余生不在挽留i 发表于 2021-1-7 12:55:03

ok

CyberYoung 发表于 2021-1-7 14:23:00

多谢老师

Aimyorcc 发表于 2021-1-7 14:53:32

参考
页: 990 991 992 993 994 995 996 997 998 999 [1000] 1001 1002 1003 1004 1005 1006 1007 1008 1009
查看完整版本: S1E2:第一个程序 | 课后测试题及答案