Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting lines of code

Status
Not open for further replies.

jd77

Programmer
Jan 2, 2001
33
US
Does anyone know of a utility that counts the lines of source code (minus comments and blank lines) in a single or multiple C/C++ source files in a Windows environment? Tried a number of things with the preprocessor, etc (VxWorks), but have not had much luck.

Thanks,

Joe
 
you can use (in run time) the macro __LINE__

printf("%d\n",__LINE__);

this count ALL lines, but give you exactly the pos in code
you are running.

if(problems) printf("PROBLEMS on line %d\n", __LINE__);
 
Basically, what you are looking for is the Windows equivalent of Unix's

egrep ";" *.cpp *.h | wc -l

This will give a rough count. It includes statements that have been commented out (hopefully very few), and semi-colons in comments (again, as we are not even taught when to use it except when you get an English teacher who is fussy about punctuation, there are very few of these). Side issue: there was a Colombo program on the other night where the bad guy used a semi-colon which Colombo said only a "well educated" person would use in the correct place.

You'd probably have to write a program to count the number of linefeeds in stdin. That should get round the wc -l. Find may work in place of egrep but there are so many variants it really depends on which version of windows you are using.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top