Opo. 发表于 2021-10-18 22:32:40

#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 findALLFilse(const char *path);

int countLines(const char *filename)
{
        FILE *fo;
        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(temo == '\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(syrcat(thePath,"/*.c"),&fa))!= -1L)
        {
                do
                {
                        sprintf(target,"%s/%s",path,fa.name);
                        titak += 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;
}
不了解怎么错了,来自电脑小白

zhangben0621 发表于 2021-10-18 22:36:47

0、听不懂人话
1、由0和1组成的机器语言
2、编译
3、编译型语言是将所有代码编译过后生成可执行文件,可执行文件是机器能直接读懂的。而解释型语言需要中间解释器逐句将字节码翻译给机器执行
4、可以
5、需要在不同的平台提供不同的解释器
6、通过不同的·和一组合来表示不同的字母、数字、符号
7、亲们,趁敌人吃饭时发动进攻

Opo. 发表于 2021-10-18 22:44:59

#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 findALLFilse(const char *path);

int countLines(const char *filename)
{
        FILE *fo;
        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(temo == '\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(syrcat(thePath,"/*.c"),&fa))!= -1L)
        {
                do
                {
                        sprintf(target,"%s/%s",path,fa.name);
                        titak += 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;
}
本人电脑小白,用dev--C++打出来不行,直接复制你的代码显示出来的是0行,是不能用dev--C++打这一串代码吗?

汉斯牛 发表于 2021-10-18 22:55:01

HHH

WILL. 发表于 2021-10-18 23:03:25

答案

暖风在身 发表于 2021-10-18 23:42:58

查看参考答案

Korliang 发表于 2021-10-18 23:43:37

查看参考答案

一条little鱼 发表于 2021-10-19 00:24:30

hellow word

开了开了 发表于 2021-10-19 08:02:35

0.他只认识机器语言.听不懂人话
1.机器语言
2.编译
3.作用不同
4.6能
5.国际规定
6.写代码,找字母
7.具有中国特色

开了开了 发表于 2021-10-19 08:03:52

S1E2;第一个程序

开了开了 发表于 2021-10-19 08:05:02

S1E2:第一个程序 | 课后测试题及答案

3010508065 发表于 2021-10-19 08:13:44

2312

人到中年不得已 发表于 2021-10-19 10:31:05

woc

永无止境的学习 发表于 2021-10-19 10:53:47

我来看看

苏苏苏凤梨苏 发表于 2021-10-19 11:00:03

SSS

KevsterCpp 发表于 2021-10-19 12:34:31

从基础开始!!好耶!!谢谢FishC老师

htf 发表于 2021-10-19 13:27:35

{:10_257:}

fohat 发表于 2021-10-19 15:12:37

牛啊

海岛冰轮 发表于 2021-10-19 15:32:48

0.计算机只能识别二进制,即0和1。
1.二进制。
2.编译型语言可以直接转化为汇编语言进而转化为机器语言,解释型语言需要解释器才能让CPU执行。
4.不太行。
5.字节码。

和尚... 发表于 2021-10-19 16:27:01

#include<stdio.h>
int main()
{
    printf("Hello World!");
    return 0;
}
页: 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 [1425] 1426 1427 1428 1429 1430 1431 1432 1433 1434
查看完整版本: S1E2:第一个程序 | 课后测试题及答案