aolods 发表于 2020-10-9 18:56:08

测试题答案

快乐的小拉达 发表于 2020-10-9 19:16:49

hh

youngers 发表于 2020-10-9 19:25:53

0

Zpy2020 发表于 2020-10-9 19:51:38


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

jxy1230 发表于 2020-10-9 20:05:48

1

GUHAN 发表于 2020-10-9 20:25:55

感谢楼主无私奉献!

1364702797 发表于 2020-10-9 20:35:26

运行不了?

glgk 发表于 2020-10-9 21:08:57

1

lightlight 发表于 2020-10-9 21:11: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("目前你总共写了 %ld 行代码! \n\n", total);
                                system("pause");
                               
                                return 0;
                }

修改了好久

四仰化三铁 发表于 2020-10-9 21:14:32

额外全额委屈恶气

C小王 发表于 2020-10-9 22:10:49

来了来了l'l

ljw233 发表于 2020-10-9 22:30:27

查看参考答案

总是难免 发表于 2020-10-9 22:44:02

1284517364 发表于 2020-10-9 23:33:51

1111111

king.脉搏 发表于 2020-10-10 00:52:50

1

ganmou 发表于 2020-10-10 01:00:02

学习

zyhhsss 发表于 2020-10-10 08:14:45

E

EVEN.C 发表于 2020-10-10 10:18:36

感谢楼主的分享

YbaizeO 发表于 2020-10-10 10:19:06

0.二进制
1.编程语言
2.编译
3.能否直接被CPU执行
4.能
5.字节码转化为解释码
6.编码和解码
7.亲们趁敌人吃饭时发动进攻

VitoQian 发表于 2020-10-10 10:33:11

第22行运行不下去了,求解
页: 884 885 886 887 888 889 890 891 892 893 [894] 895 896 897 898 899 900 901 902 903
查看完整版本: S1E2:第一个程序 | 课后测试题及答案