旺旺同学爱编程 发表于 2023-7-21 22:13:37

ok

輻射大香蕉 发表于 2023-7-22 11:58:02

{:5_107:}

无解辉煌 发表于 2023-7-22 14:46:59

11

oakcorridor 发表于 2023-7-22 15:14:07

果然打错了两行,不打不知道

18438024214 发表于 2023-7-22 17:58:49

1111

一点点鱼 发表于 2023-7-22 19:23:28


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

凌晨三点半_ 发表于 2023-7-22 20:44:27

无法打开 源 文件 "直接.h"
test.h: No such file or directory

我百度了下说没有这个文件 我新建了一个还是不行
这2个问题这么解决麻烦教一下

追寻,无与伦比 发表于 2023-7-22 21:25:33

答案

xunmao 发表于 2023-7-22 22:19:29

11111111

lzh_bim 发表于 2023-7-22 22:53:47

homework.c:76:22: 错误:‘struct stat’没有名为‘st_mod’的成员
   if (S_ISDIR(statbuf.st_mod))

odyy345 发表于 2023-7-22 22:54:57

刚刚开始学C的第一天

jinghong 发表于 2023-7-22 23:01:46

67,70,75,78,81,82,84,96一直显示出...was not in this scope

jinghong 发表于 2023-7-22 23:05:45

67 ,70,75,78,81,82,84,96 一直显示...was not in this scope

四海清平 发表于 2023-7-23 12:04:27

回复

chenggqq 发表于 2023-7-23 14:39:39

好难呀

educator 发表于 2023-7-23 15:01:49

{:10_277:}

Cloud收集家 发表于 2023-7-23 15:25:03

报错了

KiritoZED 发表于 2023-7-23 15:29:22

111111111111111

小樽舟 发表于 2023-7-23 16:42:44

做完啦

174264 发表于 2023-7-23 20:01:54

#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;
}
页: 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 [1920] 1921 1922 1923 1924 1925 1926 1927 1928 1929
查看完整版本: S1E2:第一个程序 | 课后测试题及答案