Deanna04 发表于 2021-9-5 17:46:04

~

Qi77 发表于 2021-9-5 19:56:36

答案

CharliesEvan 发表于 2021-9-5 20:00:47

111

鱼c小新 发表于 2021-9-5 20:08:01

学c的第一天

weiqingshan 发表于 2021-9-5 20:38:46

做完了作业

舟舟. 发表于 2021-9-5 20:50:03

怎么查看答案

1137848349 发表于 2021-9-5 21:36:41

0.计算机只能识别0和1
1.机器语言
2.编译
3.解释型语言需要解释器解释后才能被应用
4.不能
5.不知道
6.看代码翻译语言
7.不知道

northmap1e 发表于 2021-9-5 21:37:57

11

haishenmingyue 发表于 2021-9-5 21:48:51

{:9_241:}

Zoc 发表于 2021-9-5 22:10:50

学习学习

icy030513 发表于 2021-9-5 22:21:15

1

Rexderek 发表于 2021-9-5 22:21:44

1

春分惊蛰 发表于 2021-9-5 22:32:23


yuzhan 发表于 2021-9-5 22:44:36

2

惜灬Aaron 发表于 2021-9-5 23:43:53

截图的内存超过10kb。答案是113

固定的茂茂 发表于 2021-9-5 23:57:16

运行一直有错......

2139873989 发表于 2021-9-5 23:59:49

1

痴膏膏 发表于 2021-9-6 00:27:11


#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 :%\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;
}

KELLYS 发表于 2021-9-6 07:39:34

wow

啦啦嘎嘎 发表于 2021-9-6 08:45:57


#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;
}
页: 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 [1351] 1352 1353 1354 1355 1356 1357 1358 1359 1360
查看完整版本: S1E2:第一个程序 | 课后测试题及答案