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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:51:10+00:00 2026-05-28T19:51:10+00:00

I would like to pass a string to a function in C in which

  • 0

I would like to pass a string to a function in C in which the function will parse out a function name, the arguments for the function, and its datatypes, and then call the function for me. What is the best approach?

  • 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-28T19:51:12+00:00Added an answer on May 28, 2026 at 7:51 pm

    If you want to write a function with a format string and variable arguments like:

    int function(const char* strFormat, ... )
    {
      //parse out the format using regex or something
      //then store the data into the variable aruments
      //or create a string concatenating everything
    }
    

    like, say printf, sprintf, or scanf does,

    then the best thing for you to do is look at some good tutorials.

    http://msdn.microsoft.com/en-us/library/fxhdxye9(v=vs.80).aspx

    http://www.cprogramming.com/tutorial/c/lesson17.html

    If you are wanting to actually pass a function name for the function to call, along with its arguments, you either need to implement some form of reflection or introspection in your c code, a really complex switch statement which calls the functions for you based upon the string value, or write some complex macros to act as a sort of a secondary
    compiler.

    glib’s gobject is an excellent example of introspection in c.
    http://developer.gnome.org/gobject/stable/

    something simple without introspection may be:

    void* function (const char* strFunctionName, ... )
    {
      if(!strcmp(strFunctionName, "functionA"))
      {
        //use va_list to parse out the arguments for the function.
        functionA(//each of the arguments from va_list);
      }
      else if(!strcmp(strFunctionName, "functionB"))
      {
        //use va_list to parse out the arguments for the function.
        functionB(//args from va_list);
      }
      ...
    }
    

    If you have something more specific in mind, please specify in your question.

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

Sidebar

Related Questions

I would like to pass the multiple arguments with positive or negative values. Is
I would like to pass to a jQuery function a regular function, instead of
I would like to pass {id:1, name:stackoverflow, parameter2:false, parameter3:true} To my action public JsonResult
In my UserProfile model I would like to have a function which returns either
I would like to pass the variable from a function to the main scope
My main function contains a string that I would like to jumble. I have
I would like to compare 2 date, which stored in database as String. When
I would like to pass an argument(s) to a method being defined using define_method,
I would like to pass an x amount of geo-locations to the Google Maps
I would like to pass a reference of a method into another method and

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.