200208125 发表于 2021-11-12 18:30:51

kkkkkkkkkk

camillejiang 发表于 2021-11-12 19:22:42

{:10_254:}

xuedingbang 发表于 2021-11-12 20:01:30

我的老出错

Stephanine 发表于 2021-11-12 20:54:11

绅士之道 发表于 2021-11-12 21:38:06

666666666666666

lizehui 发表于 2021-11-12 21:57:09

1

gaolei111 发表于 2021-11-12 22:45:58

111

Itach_xx 发表于 2021-11-12 22:54:57

查看参考答案

Mr浅忆 发表于 2021-11-12 23:32:39

怎么发图片?

照洋洋洋 发表于 2021-11-13 00:01:31

解释型是如何实现跨平台这个问题有些迷惑。。

815671972 发表于 2021-11-13 01:20:43

本帖最后由 815671972 于 2021-11-13 01:32 编辑

#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;
}
"C:\Users\86185\Pictures\Screenshots\屏幕截图 2021-11-13 011419.png"
新手不知道弄得能不能看见,运行结果为:目前你总共写了 0 行代码!
为什么是0啊不知道哪里错了!!!

王轩魁 发表于 2021-11-13 10:14:27

加油

pigff123 发表于 2021-11-13 12:09:17

1

不许 发表于 2021-11-13 12:39:46

1

山东青岛 发表于 2021-11-13 14:47:04

ohiny 发表于 2021-11-13 16:14:01

1

嵌入海里面 发表于 2021-11-13 16:58:53

超棒

Mocca 发表于 2021-11-13 17:16:11

112行代码

kiliop 发表于 2021-11-13 17:56:05

beigai 发表于 2021-11-13 19:26:53

回复
页: 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 [1457] 1458 1459 1460 1461 1462 1463 1464 1465 1466
查看完整版本: S1E2:第一个程序 | 课后测试题及答案