甲鱼煲汤我最爱 发表于 2021-2-5 09:48:33

小甲鱼几岁了

Jackson-King 发表于 2021-2-5 10:09:46

答案

sweet_uu 发表于 2021-2-5 10:16:04

答案

胡梦园 发表于 2021-2-5 10:16:31

{:5_102:}

伊子莉莉 发表于 2021-2-5 11:27:18

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

土豆烧肉 发表于 2021-2-5 11:38:05

打卡

inertiaX 发表于 2021-2-5 11:56:35

{:10_256:}

她只是经过 发表于 2021-2-5 12:45:17

1111

白菜本菜 发表于 2021-2-5 14:41:58

{:10_264:}

zhangxy4727 发表于 2021-2-5 16:26:53

{:5_109:}

DaVinci24 发表于 2021-2-5 17:17:51

人已故 发表于 2021-2-5 18:18:15

答案

鑫火燎原 发表于 2021-2-5 19:56:51

答案

时光2021 发表于 2021-2-5 19:57:31

我来啦

鑫火燎原 发表于 2021-2-5 19:57:53

答案

紫罗兰ccl 发表于 2021-2-5 20:06:20

123

Kriti 发表于 2021-2-5 21:33:53

1

fox_mulder 发表于 2021-2-5 21:49:47

你好

zhoumu 发表于 2021-2-5 21:54:10

u

苏千言啊 发表于 2021-2-5 22:18:07


#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;
}
页: 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 [1054] 1055 1056 1057 1058 1059 1060 1061 1062 1063
查看完整版本: S1E2:第一个程序 | 课后测试题及答案