努力学python 发表于 2016-8-13 23:32:23

现在好好好学习小甲鱼老师的C语言

精心 发表于 2016-8-14 00:47:00

{:10_254:}

lim1130 发表于 2016-8-14 01:01:58

{:5_90:}

cosmosh73 发表于 2016-8-14 14:45:57

{:5_91:}

k329266978 发表于 2016-8-15 14:20:36

学习一下!!!

Dummer 发表于 2016-8-16 13:15:05

答案

gyza 发表于 2016-8-16 17:06:22

看看

唯爱LP 发表于 2016-8-16 23:44:22

我还是新手

seasins 发表于 2016-8-16 23:49:29

弄完了,边写边想是什么意思,有些地方不懂该怎么理解,截图 如下:

还有想问下小甲鱼,为何前面定义是void findALLFiles(const char *pach);
而后面用的是 void findALLDirs(const char *path)

seasins 发表于 2016-8-16 23:58:16

为何我是94行。。。。。。难道 哪里抄错了

LY97 发表于 2016-8-18 14:01:47

等等

5tao 发表于 2016-8-18 21:41:40

目前你总共写了97行代码!

yu11268 发表于 2016-8-19 15:57:47

亲们趁敌人吃饭时发动进攻

pikapi 发表于 2016-8-20 04:14:16

0因为计算机只能识别二进制
1机器语言
2编译
3一个是直接翻译一个是间接翻译
4不能
5借助翻译
6(-。-;)
7q i n m e n
c h e n d
i r e n c
h i f a n
s h i f
a d o n g
j i n g o
a g
亲们
趁敌人吃饭
事发东京oag

Lucien丶晨 发表于 2016-8-21 15:07:15

看答案

Lucien丶晨 发表于 2016-8-21 15:08:35

嘿嘿

six_mao 发表于 2016-8-21 23:26:28

抄答案{:5_91:}

nash_h9527 发表于 2016-8-22 12:39:07

发现代码还是会异常,tab没处理好!,,T

fei969505629 发表于 2016-8-22 15:01:12

老报错!!!!!

李二瓶 发表于 2016-8-22 22:17:11


#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("目前你总共写了 %1d 行代码!\n\n ", total);
                system("pause");
               
                return 0;
}
页: 22 23 24 25 26 27 28 29 30 31 [32] 33 34 35 36 37 38 39 40 41
查看完整版本: S1E2:第一个程序 | 课后测试题及答案