Count the number of lines of code in a project. Only the cpp file is counted.

Source: Internet
Author: User

# Include <iostream>
# Include <fstream>
# Include <direct. h>
# Include <io. h>
# Include <string>
# Include "my_dll1.hpp"
Using namespace std;
Int countLine (char * filename );
Void countBrowseLine (char * pathName, char * filetype );
Int main (int argc, char * argv [])
{
If (* (argv + 1) = NULL | * (argv + 2) = NULL)
{
Return 0;
}
Char str [50];
Strcpy (str, * (argv + 1 ));
Char type [20];
Strcpy (type, * (argv + 2 ));
CountBrowseLine (str, type );
System ("pause ");
 
Return 0;
}

Void countbrowseline (char * pathname, char * filetype)
{
_ Chdir (pathname );
_ Finddata_t fdata;
Int ntotal = 0;
Int n = 0;
Long label = _ findfirst (filetype, & fdata );
Do
{
Cout <"the lines of the" <fdata. Name <"is ";
N = countline (fdata. Name );
Ntotal + = N;
Cout <n <Endl;
} While (_ findnext (Label, & fdata) = 0 );
Cout <"all the lines of the Browse about" <filetype <"is" <ntotal <Endl;
}
Int countline (char * filename)
{
Int ncount = 0;
Fstream fin (filename );
Char c [300];
If (! Fin)
{
Cout <"file read error" <endl;
Return 0;
}
While (! Fin. eof ())
{
Fin. getline (c, 300 );
++ NCount;
}
Fin. close ();
Return nCount;
}

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.