清水由樹 发表于 2021-8-3 12:03:15

{:5_90:}

Regina0 发表于 2021-8-3 12:41:07

0

大脑空白 发表于 2021-8-3 13:16:35

1

小于不卷 发表于 2021-8-3 13:33:25


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

纪月# 发表于 2021-8-3 13:46:13

抱歉啦

小于不卷 发表于 2021-8-3 13:50:37

我运行以后显示只有13行我不知道为什么{:10_266:}

yyushyui 发表于 2021-8-3 13:51:04

0.计算机只看得懂二进制
1.机器语言
2.编译
3.编译语言是转化为汇编语言再到机器语言解释语言是转化为字节码再由解释器翻译给计算机
4.不行
5.转化为字节码再由解释器翻译给计算机
6.长短音代表线和点,不同的点线组合代表不同的字母,用字母拼凑出语言信息

YSKey 发表于 2021-8-3 14:03:21

本帖最后由 YSKey 于 2021-8-3 14:06 编辑

211行代码

印第安斑鸠蛋 发表于 2021-8-3 14:45:39

看看对不对

2605917192 发表于 2021-8-3 15:11:15

111

Zurichsee 发表于 2021-8-3 15:16:12

运行错误

hjz1147 发表于 2021-8-3 15:42:54

tnl

二厨子 发表于 2021-8-3 16:01:17

学习了

斩夜神 发表于 2021-8-3 16:09:19

0

102h355 发表于 2021-8-3 16:30:24

2021的来了

小白学不会 发表于 2021-8-3 16:40:27

程序作业

1091196248 发表于 2021-8-3 16:54:25

1

迂于与玉 发表于 2021-8-3 17:29:41

感谢分享

dmy2003 发表于 2021-8-3 17:37:01

....

晴白色 发表于 2021-8-3 17:38:26

一斤做完了
页: 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 [1296] 1297 1298 1299 1300 1301 1302 1303 1304 1305
查看完整版本: S1E2:第一个程序 | 课后测试题及答案