新房客_ 发表于 2021-8-2 20:32:22

{:5_108:}

爱学习的小鱼苗 发表于 2021-8-2 20:37:03

大爱小甲鱼

EdPan 发表于 2021-8-2 20:42:21


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

不二歌 发表于 2021-8-2 20:57:32

1

提桶跑路了 发表于 2021-8-2 21:36:07

好难啊。

仙泽 发表于 2021-8-2 21:58:07

walial

林小尖 发表于 2021-8-2 22:03:09

参与

nxbfbkn 发表于 2021-8-2 22:04:07

回复

superswagy2002 发表于 2021-8-2 22:08:29

看看答案

1059496154 发表于 2021-8-2 22:09:06

自检

superswagy2002 发表于 2021-8-2 22:09:22

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

畜生道 发表于 2021-8-2 22:33:50

0100101010011110

XCYY 发表于 2021-8-2 22:42:42

感谢楼主

12J3 发表于 2021-8-2 23:41:14

亲们趁敌人吃饭始发动静ong

刘先生5527 发表于 2021-8-3 02:34:55

计算机只能识别二进制

萝卜里 发表于 2021-8-3 07:24:13

1

echo1lGy 发表于 2021-8-3 08:06:51

查看参考答案

银尾学编程 发表于 2021-8-3 08:28:10

(0)计算机采用二进制。
(1)机器语言0,1。
(2)编译。
(3)编译型有编译的过程,解释型则没有。
(4)可以。
(5)
(6)查表。

胡狐 发表于 2021-8-3 09:02: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;
}

qingyuanne 发表于 2021-8-3 09:33:03

1
页: 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 [1291] 1292 1293 1294 1295 1296 1297 1298 1299 1300
查看完整版本: S1E2:第一个程序 | 课后测试题及答案