How to : Count line in other source code ?

How to count line of code in text file or file .cpp
(this .txt file or .cpp file is the input file of program)



and what's function for count line of only mark code


for example of this code(file input) , I want to count only "do" function that have mark //DO
The answers of program for read this code have to show "4"


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include <stdio.h>
int main ()
{
  FILE * pFile;
  int c;
  int n = 0;
  pFile=fopen ("1818.txt","r");
  if (pFile==NULL) perror ("Error opening file");
  else
  {
    do { //DO
      c = fgetc (pFile);
      if (c == '$') n++;
    }    //DO
      while (c != EOF);
    fclose (pFile);
    printf ("File contains %d$.\n",n);
  }
  return 0;
}



what's the source code for count the line of code and the line of each function


,Thank you
Last edited on
I take it this is a school assignment so I won't give away the answer.

If you want to count the lines of the do I'll give you a couple hints

1) What defines a line of code?
2) What defines the starting and ending of the do loop? Hint you'll need to use a stack w/ push & pop to track when you see the start marker for the do area because you might see other start markers and/or end markers before you reach the actual do end marker.
Topic archived. No new replies allowed.