Code calculation artifact

Source: Internet
Author: User

  • Program function: Accurately calculates the number of rows of the specified type code in all subfolders in a folder, and the artificial line breaks are automatically ignored.
  • How to: Use X-code to compile the executable file onto the desktop, double-click to open it and follow the instructions.
  • The code is as follows:
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 //Calculate lines of code5 intCountamount (Chara[])6 {7     intI,sum =0;8     9      for(i =0; A[i]; i++)Ten     { One  A         intFlag =0; -         //Find out if there is any content between this carriage return and the previous carriage return character -         if(A[i] = =Ten) { the              -              for(intj = i-1; J >0&& A[j]! =Ten; j--) { -                  -                 if(A[j]! =' '&& A[j]! = -) { +Flag =1; -                      Break; +                 } A             } at         } -         if(flag) { -sum++; -         } -     } -     //Add 1 if the last line has no line break in     if(a[i-1] !=Ten) { -sum++; to     } +     returnsum; - } the intMain () * { $     /** The Find command to execute*/Panax Notoginseng     Charcommand[ the]; -     /** Folder path that requires merging code*/ the     Charfolderpath[ the]; +     /** file suffix name*/ A     Charsuffix[ -]; the     /** A temporary file that holds all the files that have been searched, each path in this file is a separate line, and the file is deleted .*/ +     Chartempfile[ the]; -     /** pointers to temporary files*/ $FILE *Ftempfile; $     /** Single File path*/ -     Charsinglefile[ the]; -     /** Pointer to a single file*/ theFILE *Fsinglefile; -     /** Store all content in a single file*/Wuyi     Charsinglefilecontent[1000000]; the     /** Number of individual file codes*/ -     intSinglefileamount; Wu     /** Total of all file codes*/ -     intAllfileamount; About     /** Number of files*/ $     intFileNum; -     CharCh,ch2; -     intI,flag; -      while(1) A     { +printf"please drag into the folder path:"); thescanf"%s", FolderPath); -printf"Enter the suffix of the file you want to merge (for example,. c,.txt):"); $scanf"%s", suffix); the         //to generate an incomplete find command thestrcpy (Command,"Find"); the strcat (command,folderpath); thestrcat (Command,"-name *"); - strcat (command,suffix); instrcat (Command,">>"); the         //full path to generate temporary files the strcpy (tempfile,folderpath); Aboutstrcat (Tempfile,"/temp.txt"); the         //generate the complete find command the strcat (command,tempfile); the         //execute the Find command under UNIX to output the search to the Temp.txt file + System (command); -Ftempfile = fopen (Tempfile,"R"); theFileNum =0;BayiAllfileamount =0; the          while(1) the         { -i=-1; -             //get the full path of a file every time the              while((Singlefile[++i]=fgetc (ftempfile))! =Ten&&singlefile[i]!=EOF); the              the             if(singlefile[i]==EOF) the             { -                  Break; the             } thesinglefile[i]=0;//end of File content flag theSinglefileamount =0;94CH2 =0; theFsinglefile=fopen (Singlefile,"R");//Open File theI=0; the              while((Ch=fgetc (fsinglefile))! =EOF)98             { Aboutsinglefilecontent[i++] =ch; -             }101Singlefilecontent[i] =0;102Singlefileamount =Countamount (singlefilecontent);103filenum++;104printf"%d:%d Line%s\n", filenum,singlefileamount,singlefile); theAllfileamount + =Singlefileamount;106 fclose (fsinglefile);107         }108 fclose (ftempfile);109         //generate a command to delete a temporary file thestrcpy (Singlefile,"RM");111 strcat (singlefile,tempfile); theSystem (Singlefile);//Delete temporary files113printf"\ n \ ndo This folder: \ n"); theprintf"total%d. c files \ n \ nthe", FileNum); theprintf"Total code:%d lines \ n", allfileamount); the 117         118     }119     return 0; -}

    Results:

Code calculation artifact

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.