Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:13:40+00:00 2026-06-01T15:13:40+00:00

I want to find for each function defined in a C source file how

  • 0

I want to find for each function defined in a C source file how many times it’s called and on which line.
Should I search for patterns which look like function definitions in C and then count how many times that function name occurs. If so, how can I do it? regular expressions?
Any help will be highly appreciated!

#!/bin/bash
if [ -r $1 ]; then
       #??????
else    
        echo The file \"$1\" does NOT exist
fi      

The final result is: (please report any bugs)

 10 if [ -r $1 ]; then
 11         functs=`grep -n -e "\(void\|double\|char\|int\) \w*(.*)"  $1 | sed 's/^.*\(void\|double\|int\) \(\w*\)(.*$/\2/g'`
 12         for f in $functs;do
 13                 echo -n  $f\(\) is called:
 14                 grep -n $f $1 > temp.txt
 15                 echo -n `grep -c -v -e "\(void\|double\|int\) $f(.*)" -e"//" temp.txt`
 16                 echo " times"
 17                 echo -n on lines:
 18                 echo -n `grep  -v -e "\(void\|double\|int\) $f(.*)" -e"//" temp.txt | sed -n 's/^\([0-9]*\)[:].*/\1/p'`
 19                 echo
 20                 echo
 21         done    
 22 else    
 23         echo The file \"$1\" does not exist
 24 fi 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:13:41+00:00Added an answer on June 1, 2026 at 3:13 pm

    This might sort of work. The first bit finds function definitions like

    <datatype> <name>(<stuff>)
    

    and pulls out the <name>. Then grep for that string. There are loads of situations where this won’t work, but it might be a good place to start if you’re trying to make a simple shell script that works on some programs.

    functions=`grep -e "\(void\|double\|int\) \w*(.*)$" -f input.c | sed 's/^.*\(void\|double\|int\) \(\w*\)(.*$/\2/g'`
    for func in $functions
    do
      echo "Counting references for $func:"
      grep "$func" -f input.c | wc -l
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find the successor of each element in my encoded string. For
I want to find user tweet's count for each month from the time when
I want to find the centroid of each contour.for that i take some sample
I want to find internal and external back-links for each urls of sitemap.xml. I
I want to find any text in a file that matches a regexp of
Given a tree, I want to find the paths from the root to each
I want find all Saturdays and Sundays in A given month. How can I
I want to find records on a combination of created_on >= some date AND
I want to find a way to develop database projects quickly in Visual Studio.
I want to find out all the subdomains of a given domain. I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.