WANTED: "C" code line counter program

Michael W. Balk mwb at ulysses.att.com
Thu Mar 14 14:06:48 AEST 1991


In article <1991Mar11.182848.26693 at comm.wang.com>, lws at comm.wang.com (Lyle Seaman) writes:
> dcavasso at ntpal.uucp (Dana Cavasso) writes:
> >     I need a "C" code line counter program, preferably written in
> >"C".  It will be used on several platforms, so solutions involving
> 
> Counting semi-colons is a pretty good approach, as that counts C 
> statements.  Lines is kind of less meaningful.  Counting '{' is 
> an interesting one, too.


If you just count semi-colons, then in for-loops such as

	for(i = 0; i < 10; i++)
	  {
	     ...
	  }


i = 0; and i < 10; will be counted as individual statements.
In fact they are, but if you want to count for( ... ) as a single statement
then count the semi-colons and correct the count by subtracting 1 for every
for-statement.  There might be other cases like this that you may want to
consider.  Then again, in most cases this is just probably nit-picking.



More information about the Comp.lang.c mailing list