PisoN 发表于 2024-5-2 22:46:00

鱼C有你更精彩^_^

Yiin. 发表于 2024-5-3 15:48:34

204

ii斩魂 发表于 2024-5-3 20:51:37

OK了

红蔷薇白玫瑰 发表于 2024-5-4 19:41:20

{:5_108:}

black__ 发表于 2024-5-5 09:50:01

看看答案

Neymar1011 发表于 2024-5-5 15:43:03

h

xiaoyu.c 发表于 2024-5-5 19:21:01

一起学习,鱼c666

春和景明y 发表于 2024-5-5 21:14:48

机器语言,编译

王丶胖 发表于 2024-5-6 15:08:10

查看答案

LLLLLUO 发表于 2024-5-6 19:26:47

聿酉延 发表于 2024-5-6 20:44:19


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

章若楠同学 发表于 2024-5-6 21:24:49

1

zhenhao116 发表于 2024-5-7 13:08:22

鱼C有你更精彩^_^

哈波特。杰克 发表于 2024-5-7 14:02:01

1

金流儿 发表于 2024-5-7 14:56:12

本帖最后由 金流儿 于 2024-5-7 14:57 编辑

我的编译不出来,复制粘贴也编译不出来。
/usr/lib/gcc/i686-redhat-linux/4.8.5/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status

故落汐妖 发表于 2024-5-7 21:28:43

1

弱小无助 发表于 2024-5-8 15:19:35

查看

CyyZJUGO 发表于 2024-5-8 15:43:08

1

Tchaikov_Hoo 发表于 2024-5-8 22:09:02

想查看下参考答案~~
中途有个countLines被敲成countlines了~~

小杜要c 发表于 2024-5-8 22:48:51

我没打开
页: 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 [2026] 2027 2028 2029 2030 2031 2032 2033 2034 2035
查看完整版本: S1E2:第一个程序 | 课后测试题及答案