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 Ex 2: For pre 3: for Program that only count // block depth 1
{if () {}} // block depth of 2
{for () {if () {}}} // block depth 3
// & 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
Post a Comment