月梦剑影 发表于 2022-8-17 12:16:01

aa

abnormore 发表于 2022-8-17 18:11:14

666

fallingstar 发表于 2022-8-17 18:26:49

从头到尾查了一遍错误终于成功运行程序了,

STRIV1 发表于 2022-8-17 20:43:49

11

启政在学习 发表于 2022-8-17 21:38:39

吴会

xiaoyuera 发表于 2022-8-17 22:23:22

daan

硬核以太 发表于 2022-8-18 00:34:21


#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 _finddate_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_finddate_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);
                                          findALLDirsa(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;
}

li07467227429 发表于 2022-8-18 08:46:51

本帖最后由 li07467227429 于 2022-8-18 08:52 编辑

写完了

15635284731 发表于 2022-8-18 11:24:53

好好好

Renee_87 发表于 2022-8-18 14:27:02

对答案{:10_279:}

zuinulidexing 发表于 2022-8-18 14:47:52

{:5_104:}

tomato111 发表于 2022-8-18 16:19:33

5.

XxxtentaH 发表于 2022-8-18 16:20:53

为什么一直显示未定义标识符

喜欢悠哉Visky 发表于 2022-8-18 17:17:29

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

c12138f 发表于 2022-8-18 18:52:01

1

二向箔_ 发表于 2022-8-18 19:43:50

学习

语文社 发表于 2022-8-18 20:21:10

学习学习

xuweiquan 发表于 2022-8-18 20:54:40

参考答案

Alexander_Li 发表于 2022-8-18 22:43:53

yes

lyc51566 发表于 2022-8-18 22:53:28

.
页: 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 [1709] 1710 1711 1712 1713 1714 1715 1716 1717 1718
查看完整版本: S1E2:第一个程序 | 课后测试题及答案