Click here to Skip to main content
13,197,342 members (57,470 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 25 Feb 2006

Code Statistic Assistant

, 2 Mar 2006
Rate this:
Please Sign up or sign in to vote.
A C/C++, Datastrcture and Win32 API Project


This project for my deeper understand in C/C++ and Win32 API. I know this implementation is not nice enough, but it runs well. In this file, the program trait will be explain. And give some descriptions about the structure and example. I use the C Version to describte this project, but as you see, you can down a Cpp Version.


1) Run in command line/with parameters
2) easy to use.
3) statistic file which type include .txt, .C, .C++, .h, .java.
4) it can deal with specific files, or specific directory(include sub-directory).
5) Set valid file for statistic.

Data Structure

The purpose of this secssion is to describe structures. Including
struct LIB , ITEM and CMDMSG. CMDMSG, which i define as command
message, is a message which take parameters and command type use in
*The definition of struct ITEM, which use to record the statistic info.
typedef struct ITEM{
char filename[ FILE_NAME_MAX_LEN + 1 ];
char path[ PATH_MAX_LEN + 1 ];
FILE_T type;
long totalLine;
long commentLine;
long bankLine;
long codeLine;
*The definition of struct LIB, which use to record the LIB info.
typedef struct LIB{
long totalCode; //total line
long comment; //comment line
long bank; //bank line
long code; //code line
long sizTab; //size of table
long HeaderNUM; //header file counter
long CNUM; //C source file counter
long CppNUM; //C++ source file counter
long TxtNUM; //txt file counter
long JavaNUM; //java source file counter
double result; //result = ( comment + bank ) div totalCode
BOOL fStat; //statistic flag
BOOL fModify; //modification flag
TABLE table;
char szLibName[ FILE_NAME_MAX_LEN + PATH_MAX_LEN + 1 ];
*The definition of command message(CMDMSG) & its handle(HCMDMSG).
*Note: firARG is a pointer to first argument, it may be a filename / NULL
* secARG is variable signed state/FILE_T
* pFindArg is a pointer to find argument struct
typedef struct CMDMSG{
CMD_T command;
char *firARG;
int secARG;

A simple API example

The function StatUnderDirHelp uses Win32 API, FindFirstFile, FindNextFile and FindClose.

static BOOL StatUnderDirHelp(PLIB pLib, char *szDir, char *szType)
char szFileName[256];
char szTmpFileName[256];
BOOL flag;

strcpy( szFileName, szDir );
strcat( szFileName, "\\" );
strcat( szFileName, szType );

hFind = FindFirstFile( szFileName, &FindData );
while ( hFind != INVALID_HANDLE_VALUE )
strcpy( szTmpFileName, szDir );
strcat( szTmpFileName, "\\" );
strcat( szTmpFileName, FindData.cFileName );
pItm = MakeItem();
strcpy( pItm->filename, FindData.cFileName );
strcpy( pItm->path, szDir );
if ( ( flag = StatFile( pItm, szTmpFileName ) ) == FILE_OPEN_ERR )
FindClose( hFind );
FreeItem( pItm );
if ( flag != INVAILD_FILE )
if ( AddItem( pLib, pItm ) == MEM_EMPTY )
FindClose( hFind );
return MEM_EMPTY;
if ( !FindNextFile( hFind, &FindData ) )
FindClose( hFind );
return SUCCESS;


Contact me if you have some comments or found bugs.(


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
China China
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralAbout your article... Pin
Geert van Horrik25-Feb-06 23:12
memberGeert van Horrik25-Feb-06 23:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 3 Mar 2006
Article Copyright 2006 by sense_8
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid