how can count how many variables from file in c code and also find how many function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moronjoe
    New Member
    • Feb 2018
    • 2

    how can count how many variables from file in c code and also find how many function

    how can count how many variables from file in c code and how many
    function in c file please give answer write a c/c++ code
    thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Are you trying to write a compiler? This is not a simple problem. If this is a homework problem, do you have a particular C file you are supposed to be using?

    Comment

    • moronjoe
      New Member
      • Feb 2018
      • 2

      #3
      no , i read a file than count how many function in there but i could not <C file>

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        It is easier to parse a compiled object file than a C source file.
        It is even easier to use a language like Perl to process the output of an object file parsing tool such as nm.

        Is a list of symbols sufficient or do you need to distinguish function and variable names?
        Is a list of global names sufficient or do you need to also get the local (static) names?

        If you must parse a source file, are you allowed to enforce a no-typedefs rule? Typedefs complicate the source-parsing logic.

        Can you parse the output of the C preprocessor or are you required to recognize and deal with macro definitions, macro references, conditional compilation, etc?
        Last edited by donbock; Feb 27 '18, 11:20 AM. Reason: Added note about the preprocessor.

        Comment

        Working...