ÓãCÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
²é¿´: 3986|»Ø¸´: 7

[Òѽâ¾ö]windowsϵͳΪʲôÎҵĵÚÒ»¿Î´úÂëÔËÐÐÖ®ºóÏÔʾ:ÎÒÒÑдÁË0ÐдúÂ룿²»Ó¦¸ÃÊÇ

[¸´ÖÆÁ´½Ó]
·¢±íÓÚ 2020-9-26 11:46:27 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ

ÂíÉÏ×¢²á£¬½á½»¸ü¶àºÃÓÑ£¬ÏíÓøü¶à¹¦ÄÜ^_^

ÄúÐèÒª µÇ¼ ²Å¿ÉÒÔÏÂÔØ»ò²é¿´£¬Ã»ÓÐÕ˺ţ¿Á¢¼´×¢²á

x

#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 findALLCodes(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[MAX], target[MAX];
            
            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[MAX];
       
        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[MAX] = ".";
       
        printf("¼ÆËãÖÐ...\n");
       
        findAllCodes(path);
        findALLDirs(path);
       
        printf("ÄãĿǰ×ܹ²Ð´ÁË %1d ÐдúÂ룡 \n\n", total);
        system("pause");
       
        return 0;
}
×î¼Ñ´ð°¸
2020-9-26 12:26:47
²âÊÔÁËһϴúÂ벢ûÓдí,ÄǾÍÓ¦¸ÃÊǺó׺ÃûµÄÎÊÌâÁË,°Ñ³ÌÐòµÄºó׺Ãû¸ÄΪ.c
»òÕß°Ñ
  1. if ((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
¸´ÖÆ´úÂë
¸ÄΪ
  1. if ((handle = _findfirst(strcat(thePath, "/*.cpp"), &fa)) != -1L)
¸´ÖÆ´úÂë
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2020-9-26 11:54:44 | ÏÔʾȫ²¿Â¥²ã
  1. #include <io.h>
  2. #include <direct.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>

  6. #define MAX 256

  7. long total = 0 ;

  8. bool filter(const char * fn)
  9. {
  10.         bool ret                                                                                                                       ;
  11.         int k , m                                                                                                                      ;

  12.         ret = false                                                                                                                    ;
  13.         m = strlen(fn)                                                                                                                 ;
  14.         for(k = m - 1 ; k > 0 && fn[k] != '.' ; k --)                                                                                  ;
  15.         if((k > 0 && k < m - 1) && (! stricmp(& fn[k] , ".c") || ! stricmp(& fn[k] , ".h") || ! stricmp(& fn[k] , ".cpp"))) ret = true ;
  16.         return ret                                                                                                                     ;
  17. }

  18. int countLines(const char * filename)
  19. {
  20.         FILE * fp                                                ;
  21.         int count = 0                                            ;

  22.         if((fp = fopen(filename , "r")) != NULL) {
  23.                 while(! feof(fp)) if(fgetc(fp) == '\n') count ++ ;
  24.                 fclose(fp)                                       ;
  25.         } else {
  26.                 count = - 1                                      ;
  27.         }
  28.         printf("%6d | %s\n" , count , filename)                  ;
  29.         return count                                             ;
  30. }

  31. void findall(const char * path)
  32. {
  33.         struct _finddata_t fa                                                                       ;
  34.         long handle                                                                                 ;
  35.         char bf[MAX] , wb[MAX]                                                                      ;
  36.         int m                                                                                       ;

  37.         strcpy(bf , path)                                                                           ;
  38.         if(bf[strlen(bf) - 1] != '\\') strcat(bf , "\")                                            ;
  39.         strcpy(wb , bf)                                                                             ;
  40.         strcat(wb , "*.*")     ;
  41.         if((handle = _findfirst(wb , & fa)) != -1L) {
  42.                 strcpy(wb , bf)                                                                     ;
  43.                 strcat(wb , fa . name)                                                              ;               
  44.                 if (fa . attrib & _A_SUBDIR) {
  45.                         if(strcmp(fa . name , ".") && strcmp(fa . name , "..")) findall(wb)         ;
  46.                 } else {
  47.                         if(filter(wb) && ((m = countLines(wb)) > 0)) total += m                     ;
  48.                 }
  49.                 while(! _findnext(handle , & fa)) {
  50.                         strcpy(wb , bf)                                                             ;
  51.                         strcat(wb , fa . name)                                                      ;               
  52.                         if (fa . attrib & _A_SUBDIR) {
  53.                                 if(strcmp(fa . name , ".") && strcmp(fa . name , "..")) findall(wb) ;
  54.                         } else {
  55.                                if(filter(wb) && ((m = countLines(wb)) > 0)) total += m              ;                     
  56.                         }
  57.                 }
  58.                 _findclose(handle)                                                                  ;
  59.         }                        
  60. }

  61. int main(void)
  62. {
  63.         char wb[MAX]                                                 ;

  64.         total = 0                                                    ;
  65.         printf("Input the search path [exit]: ")                     ;
  66.         scanf("%s" , wb)                                             ;
  67.         if(strlen(wb) > 0) {
  68.                 findall(wb)                                          ;
  69.                 printf("    Total source code lines : %d\n" , total) ;
  70.         }
  71. }
¸´ÖÆ´úÂë
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2020-9-26 12:02:49 | ÏÔʾȫ²¿Â¥²ã
ÎÒÒ²ÏëÖªµÀЦ¿Þ
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2020-9-26 12:19:52 | ÏÔʾȫ²¿Â¥²ã
´úÂëû´íµÄ»°,¾Í¿´×Ô¼º³ÌÐòµÄºó׺Ãû,Èç¹ûÊÇcppµÄ»°¸ÄΪc
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2020-9-26 12:26:47 | ÏÔʾȫ²¿Â¥²ã    ±¾Â¥Îª×î¼Ñ´ð°¸   
²âÊÔÁËһϴúÂ벢ûÓдí,ÄǾÍÓ¦¸ÃÊǺó׺ÃûµÄÎÊÌâÁË,°Ñ³ÌÐòµÄºó׺Ãû¸ÄΪ.c
»òÕß°Ñ
  1. if ((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
¸´ÖÆ´úÂë
¸ÄΪ
  1. if ((handle = _findfirst(strcat(thePath, "/*.cpp"), &fa)) != -1L)
¸´ÖÆ´úÂë
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
 Â¥Ö÷| ·¢±íÓÚ 2020-9-26 13:01:11 | ÏÔʾȫ²¿Â¥²ã
baige ·¢±íÓÚ 2020-9-26 12:26
²âÊÔÁËһϴúÂ벢ûÓдí,ÄǾÍÓ¦¸ÃÊǺó׺ÃûµÄÎÊÌâÁË,°Ñ³ÌÐòµÄºó׺Ãû¸ÄΪ.c
»òÕ߰ѸÄΪ

¸Ðл´óÀÐȷʵÈç´Ë£¬²»¹ýÕâÊÇÎªÊ²Ã´ÄØ
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2021-7-22 13:07:06 | ÏÔʾȫ²¿Â¥²ã
baige ·¢±íÓÚ 2020-9-26 12:26
²âÊÔÁËһϴúÂ벢ûÓдí,ÄǾÍÓ¦¸ÃÊǺó׺ÃûµÄÎÊÌâÁË,°Ñ³ÌÐòµÄºó׺Ãû¸ÄΪ.c
»òÕ߰ѸÄΪ

ÍÛ£¡¸Ðл¸Ðл£¬ÎÒÒ²ÃÔ»óÁ˺þÃ
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2022-1-13 15:22:25 | ÏÔʾȫ²¿Â¥²ã
±¾Ìû×îºóÓÉ Éϰ¶µÄ½Û×Ó ÓÚ 2022-1-13 16:12 ±à¼­
baige ·¢±íÓÚ 2020-9-26 12:26
²âÊÔÁËһϴúÂ벢ûÓдí,ÄǾÍÓ¦¸ÃÊǺó׺ÃûµÄÎÊÌâÁË,°Ñ³ÌÐòµÄºó׺Ãû¸ÄΪ.c
»òÕ߰ѸÄΪ


ΪʲôÎÒ¸ÄÁËÒÔºóÔËÐеĽá¹ûÊÇ

¼ÆËãÖÐ...
Can not open the file: ./hello world.cpp
Can not open the file: ./³­.cpp
ĿǰÄã×ܹ²Ð´ÁË 0 ÐдúÂ룡

hello world.cppÊǽÌѧÊÓÆµ¸ú×ö£¬³­.cpp¾ÍÊǿκó×÷Òµ

¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª
´òÈÅÁË ¶ÁÎļþµÄʱºò°Ñr´ò³ÉÁËf
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | Á¢¼´×¢²á

±¾°æ»ý·Ö¹æÔò

СºÚÎÝ|ÊÖ»ú°æ|Archiver|ÓãC¹¤×÷ÊÒ ( ÔÁICP±¸18085999ºÅ-1 | ÔÁ¹«Íø°²±¸ 44051102000585ºÅ)

GMT+8, 2025-7-6 22:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí