Skip to main content
gamedev.net
🔒 Locked

lines of code...

Started by Phillk6751 1 reply 300+ views
Original Post
Phillk6751
Phillk6751
in msvc++6.0 i can figure out how many lines of code are in ONE file of my project but is there a way for it to tell you how many lines of code are in your TOTAL project? if so how?
Drazgal
Drazgal
heres something I wrote a while back to do that, kinda naff but it was only a quick 5 min job, just compile it as a console program and type the path of the project folder, just make sure there arn''t any gaps as cin doesnt do them and I never got around to improving it


  
#include <fstream.h>
#include <windows.h>
#include <io.h>
#include <string.h>

void Count(char FullPath[561],int& Total,char FilePath[260]);

int main()
{
char PathName[300];
char FullPath[561];
int Counter = 0;
int Total = 0;
cin >> PathName;

SetCurrentDirectory(PathName); // Set directory to working one


struct _finddata_t c_file; // Struct to hold data

long hFile; // File handle


if( (hFile = _findfirst( "*.cpp", &c_file )) == -1L ) // Search for a file

{} // If not file found

else
{
strcpy(FullPath,PathName);
strcat(FullPath,"\\");
strcat(FullPath,c_file.name);
Count(FullPath,Total,c_file.name);

while( _findnext( hFile, &c_file ) == 0 ) // keep going til no files found

{
strcpy(FullPath,PathName);
strcat(FullPath,"\\");
strcat(FullPath,c_file.name);
Count(FullPath,Total,c_file.name);

}
_findclose( hFile ); // Close file

}

if( (hFile = _findfirst( "*.h", &c_file )) == -1L ) // Search for a file

{} // If not file found

else
{
strcpy(FullPath,PathName);
strcat(FullPath,"\\");
strcat(FullPath,c_file.name);
Count(FullPath,Total,c_file.name);

while( _findnext( hFile, &c_file ) == 0 ) // keep going til no files found

{
strcpy(FullPath,PathName);
strcat(FullPath,"\\");
strcat(FullPath,c_file.name);
Count(FullPath,Total,c_file.name);

}
_findclose( hFile ); // Close file

}

cout << Total << " Lines in total\n";

return 0;
}

void Count(char FullPath[561], int& Total,char FilePath[260])
{
int Counter = 0;
ifstream fin(FullPath);
char ch;
while(fin.get(ch))
{
if(ch == ''\n'')
Counter++;
}
Counter++;
fin.close();
cout << FilePath << " has " << Counter << " Lines\n";
Total += Counter;
}


Ballistic Programs
Phillk6751
Phillk6751
wow!!!! thanks man...its a neat little program...you can also just put it in the project folder yourself and hit "." and enter and not have to worry about spaces in the folders, address etc.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.