zzh111 发表于 2020-7-19 10:29:26

查看答案

黄白白 发表于 2020-7-19 10:40:36

D:\C\C练习

19年 发表于 2020-7-19 12:02:04

1

observation 发表于 2020-7-19 12:10: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("目前你总共写了 %1d 行代码! \n\n",total);
              system("pause");
             
              return 0;
}

ilovesxfx 发表于 2020-7-19 13:16:22

5555

Dididadali 发表于 2020-7-19 13:48:59

1

小咸鱼冲冲冲 发表于 2020-7-19 15:46:19

1

二七 发表于 2020-7-19 15:56:08

打卡

不想秃头x 发表于 2020-7-19 16:11:07

啊感谢

布尔 发表于 2020-7-19 16:59:14

嘿,亲爱的鱼油,每天都要过得开心哦^_^

nicebob 发表于 2020-7-19 17:00:01

huifudana

飞雪浮云 发表于 2020-7-19 17:01:40

回复回复

秋是啾的秋 发表于 2020-7-19 17:13:17

检查答案来啦

科科都不挂 发表于 2020-7-19 17:15:42

图片

dominic666 发表于 2020-7-19 17:16:34

打卡

小任同学 发表于 2020-7-19 17:35:55

1

xiakaicd 发表于 2020-7-19 17:38:52

谢谢老师!

dominic666 发表于 2020-7-19 17:49:01

为啥显示0行?复制粘贴也是0行。。。怎么解决

Cospy 发表于 2020-7-19 18:32:02

看不懂摩斯密码

vioiris 发表于 2020-7-19 18:43:01

1.计算机只能读取二进制代码
2.机器语言
3.编译
4.编译型语言由汇编语言转为机器语言可直接由CPU执行,而解释型语言则由解释器翻译字节码给CPU执行,这样的好处是可以跨平台
5.解释型语言则由解释器翻译字节码给CPU执行
6.由密码表来翻译点.和一
7.emmmmm
页: 765 766 767 768 769 770 771 772 773 774 [775] 776 777 778 779 780 781 782 783 784
查看完整版本: S1E2:第一个程序 | 课后测试题及答案