QLJJJ 发表于 5 天前

{:10_254:}

JBR1080 发表于 4 天前

依然重新学习C语言中

小蒋jyk 发表于 4 天前

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

#define MAX    256

long total;

int countlines(const char*dilename);
void findALLCodes(const char*path);
void findALLDirs(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 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;
}

小蒋jyk 发表于 4 天前

小蒋jyk 发表于 2026-4-21 12:59
#include
#include
#include


能问一下,我为什么运行后显示写了0行代码呀?

wufangle 发表于 4 天前

查看参考答案

IUTIME 发表于 3 天前

看不懂

懵逼医药公司 发表于 3 天前

{:9_219:}

libocheng 发表于 3 天前

1

zs111 发表于 前天 12:13

1

changchang_ 发表于 昨天 16:46

查看答案

这是熘肉段 发表于 昨天 22:40

1.因为计算机只能够接受二进制语言或者是属于计算机的程序语言像机器语言。
2.CPU唯一认识的语言是机器语言。
3.编译型语言直接能够输入计算机,而解释型语言需要解释器进行转换后输入计算机。
4,可以
5.通过C语言。
6.查表
7.对照着查出来了,翻译的实在不像人话,就不打了。
页: 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 [2139]
查看完整版本: S1E2:第一个程序 | 课后测试题及答案