Suzuya-c 发表于 2021-9-13 15:58:27

yyds

取名字太难了 发表于 2021-9-13 16:01:42

好 谢谢小甲鱼

勇敢小苏 发表于 2021-9-13 16:07:12

真不错

白谦终 发表于 2021-9-13 16:37:35

尝试一下?

我要稳稳的幸福 发表于 2021-9-13 17:01:30

1

zhaosiiyu 发表于 2021-9-13 17:12:12

看看答案

Anonymous 发表于 2021-9-13 17:36:41

好长

Lunatic007 发表于 2021-9-13 17:37:24

动动手也有答案?

很酷1212 发表于 2021-9-13 18:47:15

1

白格911 发表于 2021-9-13 19:38:06

你能体会到写完最后一个大括号,不能保存,按esc没用的感觉吗

菜鸡鱼 发表于 2021-9-13 20:12:21

C:\Users\hang\Pictures\Saved Pictures

刘楚 发表于 2021-9-13 20:25:26

0.

lpsxfy 发表于 2021-9-13 20:27:06

11111

Nhckdvrl 发表于 2021-9-13 20:48:10

代码真的太长了,抄错了,完全不知道哪里出问题

liu905407979 发表于 2021-9-13 21:22:58

代码太多啦

hhuan_huan 发表于 2021-9-13 21:35:43

0

关小淑 发表于 2021-9-13 22:59:36

ok了

白露浓霜华 发表于 2021-9-13 23:08:12

加油

詹姥爷 发表于 2021-9-13 23:10:38

哪里可以看这些单词是啥意思

YLJM 发表于 2021-9-13 23:11:51


#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 = _findfiret(strcat(thePath, "/*"), &fa)) == -1L)
      {
                frintf(stderr, "The path %s is wrong!\n",path);
                return;
      }
      
      do
      {
            if(!strcmp(fa.name, ".") || !strcmp(fa.name, ".."))
                  continue;
            
            if( fa.attriib == _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;
}
页: 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 [1366] 1367 1368 1369 1370 1371 1372 1373 1374 1375
查看完整版本: S1E2:第一个程序 | 课后测试题及答案