扶疏碎琼半痕雪 发表于 2021-4-14 20:52:20

瞅瞅答案

jkzdjk 发表于 2021-4-14 20:55:41

1

兆兆兆 发表于 2021-4-14 21:09:14

#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,"/*.cpp"),&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;
}


兆兆兆 发表于 2021-4-14 21:09:55

但是我统计不了呜呜呜

计算中...
Can not open the file:.class2.cpp
,Can not open the file:.daimazongshu.cpp
,Can not open the file:.hello world.cpp
,目前你总共写了 0 行代码!

请按任意键继续. . .

我尽量错开哈哈 发表于 2021-4-14 21:18:57

{:5_90:}

涔魂帝 发表于 2021-4-14 21:32:08

第一天学习

酱豆子 发表于 2021-4-14 22:21:28

有错误运行不了

会飞的yang 发表于 2021-4-14 22:56:05

1

疯子在流浪 发表于 2021-4-14 23:37:11

这个丑、怎么操作,是写代码到本栏内还是打开虚拟机打代码

筱寂 发表于 2021-4-14 23:42:18

萌新第一节课!

涔魂帝 发表于 2021-4-14 23:45:30

空格键跟tab不一样
我哭了

2425758776 发表于 2021-4-15 04:36:26

我选择看看

剪子布 发表于 2021-4-15 07:17:13

11111111111

Chyaevilra 发表于 2021-4-15 09:48:48

我这里总是显示path没被定义...

出汗了吧弟弟 发表于 2021-4-15 10:04:24

1

两颗柚子 发表于 2021-4-15 10:18:20

可以可以,学会了

slkd 发表于 2021-4-15 10:58:38

查看

slkd 发表于 2021-4-15 10:59:30

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

跟着小甲鱼学习 发表于 2021-4-15 11:02:12

只认识0和1
机器语言
编译

lilymaner 发表于 2021-4-15 13:36:49

daan
页: 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 [1158] 1159 1160 1161 1162 1163 1164 1165 1166 1167
查看完整版本: S1E2:第一个程序 | 课后测试题及答案