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 604477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:02:34+00:00 2026-05-13T17:02:34+00:00

Given the function name and the number of how many parameters the function has,

  • 0

Given the function name and the number of how many parameters the function has, how to list all the function definitions using egrep and regex?

For example, the name of the function is “find” we are expected to find those functions “find” that have just three parameters, no more and no less like the following:

sometype find ( type1 para1 , type2 para 2 , type3 para 3 )

I try to solve the problem by myself as:

egrep "find" * | egrep "([^,]\*,[^,]\*,[^,]\*)"

but it doesn’t work. So I need your help to point out what’s wrong with the regex I used and give me your solution to the “name : find number of parameters: 3” problem if possible.

  • 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-05-13T17:02:35+00:00Added an answer on May 13, 2026 at 5:02 pm

    Using regexes is not reliable, doubly not with egrep, unless you follow some conventions and don’t do anything too hard.

    Consider:

    void *
    function(
        int a,
        void (*pointer)(const char *, int, double),
        double d
    )
    

    This declaration is spread over 6 lines – and egrep only looks at one line at a time.

    This declaration contains 5 commas and 3 parameters.

    If you put enough restrictions on the code you are searching, you can probably get an approximation to what you are after, but C and C++ are both very hard to analyze. And I’m not even thinking about macros that invoke the function for you.


    Your proposed solution has a number of flaws, even after solving the problem with the extraneous backslashes (diagnosed correctly by Tim Pietzcker):

    egrep "find" * | egrep "\([^,]*,[^,]*,[^,]*\)"
    

    This will discover lines such as:

    find(1, 2, 3);
    int extra_find(int a, int b, int c) { ... }
    extraordinary(find, 3, 21);
    printf("find: %.*s\n", 13, "heliotrope");
    for (find(1); printf("%d %d\n", 1, 2); x++)
    for (x(find, 1); b < max(c, d); i++)
    /* find(1,2,3) */
    

    Only one of those is a function definition, and that still isn’t one of the outputs you wanted.

    If you can play with Perl (or Python) or any tool with PCRE (Perl-Compatible Regular Expressions) or equivalent, then you can do things like ensure that on a single line the word ‘find’ appears followed by an open parenthesis, a sequence of ‘type name’ values separated by commas and white space, and a close parenthesis.

    perl -ne 'print if m/\bfind\s*\(\w+\s+\w+(\s*,\s*\w+\s+\w+){2}\s*\)/'
    

    But that doesn’t handle pointers, arrays, qualifiers like ‘const’, or pointers to functions (or references, if you are using C++), or structures referenced by ‘struct somename varname’, or function definitions protected against macro expansion (int (getchar)(int c)), or … And it still doesn’t distinguish between declarations and definitions!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How they're stored in the repo isn't terribly important since… May 14, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer There's a good implementation of request local variables in Paste:… May 14, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer Making the request asynchronous would allow for better scalability of… May 14, 2026 at 6:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.