c - Counting the depth of loops -


I'm not sure whether this question is suitable for SO or not or not. I will not destroy it if it is not.

I have to review the code of some code. As part of this, I have to check the depth and position of the loops. [Please see the example given below]

If it is more than five, then I have to take care of it.

My question is, "Is there a tool that can do this for me?" I did a Google search, but I could not find any answer.

Ex 1: For // block depth 1

Ex 2: For {if () {}} // block depth of 2

pre 3: for {for () {if () {}}} // block depth 3

Program that only count

  // & gt; Prog file // & gt; Include Contract File Maximum_Direct # & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #define DEPTH_MAX 5 // A counting top level int main (int argc, char * argv []) {FILE * fp; Int depth_max = DEPTH_MAX; If (argc> 1) {if (NULL == (fp = fopen (argv [1], "r"))) {false ("fopen"); Exit (EXIT_FAILURE); }} Else {fp = stdin; } If (argc == 3) depth_max = atoi (argv [2]); Int ch, level = 0; Size_t line_no = 1; While (EOF! = (Ch = fgetc (fp))) {if (ch == '\ n') {++ line_no; } Else if (ch == '{'} {if (++ level> gt_max) printf ("found in line number:% zu \ n", line_no);} and if (ch == '}') { --level;}} Exit (EXIT_SUCCESS); Returns 0;}    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -