Counting functions in C source code

后端 未结 6 923
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 08:17

I have complete project in C, which can be built with gcc or Visual Studio. There are no calls to external libraries.

I would like to know how many functions there

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-19 08:21

    i have an idea to count the functions .c file.. wecan count this .java file also. this is c# class file and you can pass the file to the the class

    class CountFunctions
    {
    
        private FileInfo File;
        private int functions = 0;
    
        public int getNumberOfFunctions
        {
            get { return functions; }
        }
    
        public countfunctions(FileInfo fs) {
            File = fs;
            getLineOfCode();
        }
    
        private void getLineOfCode()
        {
            string line;
            try
            {
                StreamReader reader = File1.OpenText();
                while (true)
                {
                    line = reader.ReadLine();
    
                    if (IsFunction(line))
                    {
                        Functions++;
                    }
    
                    if (line == null)
                        break;
                }
            }
            catch (Exception r)
            {
                Console.WriteLine(r.Message);
            }
    
        }
    
        private bool IsFunction(string line)
        {
            if (line.Contains("void") || line.Contains("int") || line.Contains("short") || line.Contains("long") || line.Contains("float") || line.Contains("char") || line.Contains("double"))
            {
                if (!line.Contains(";"))
                {
                    return true;
                }
            }
            return false;
        }
    } 
    

提交回复
热议问题