阿潘 发表于 2022-10-31 16:54:02

a

1951063853 发表于 2022-10-31 17:04:11

1

超级璇璇1120 发表于 2022-10-31 17:43:22

{:5_109:}

yaoz7 发表于 2022-10-31 17:44:26


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

fz学c 发表于 2022-10-31 18:59:05

敲代码师傅雨熙 发表于 2022-10-31 19:46:02

2022.10.31打卡

xyl2022.10.2 发表于 2022-10-31 21:09:32

s1e2
只能执行不能思考
机器语言
编译
都为了让机器为人类所用
编译型在写好代码后直接转换为机器语言,解释型在使用时转换

转换成机器语言
硬盘存储原理


learner 的密码:
root@learner-virtual-machine:/home/learner/学c# ./callline
计算中...
目前你总共写了 112 行代码!

OGS 发表于 2022-10-31 21:28:52

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

说句晚安听吧 发表于 2022-10-31 22:55:57

6

蓝胖子蓝 发表于 2022-10-31 23:34:53

哒哒哒

212313 发表于 2022-11-1 07:06:05

加油加油

gufhitfb 发表于 2022-11-1 08:33:36

1

棠诗颂词 发表于 2022-11-1 08:48:24

66666666666666666666

小熊星期几 发表于 2022-11-1 09:54:32

0

王子王 发表于 2022-11-1 13:58:01

我抄完了也没法运行啊,我用的是visual studio 2013

CCSSR 发表于 2022-11-1 15:54:32

{:5_95:}

sddbldd 发表于 2022-11-1 16:49:06

11

熙熙熙熙熙 发表于 2022-11-1 16:57:22

1

15048811544 发表于 2022-11-1 17:29:07

答案

niuniuniuniuniu 发表于 2022-11-1 18:39:02

{:5_90:}
页: 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 [1795] 1796 1797 1798 1799 1800 1801 1802 1803 1804
查看完整版本: S1E2:第一个程序 | 课后测试题及答案