473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to call a function dynamically in C like reflections in java

Hi
I am trying to get a name of the function from the user and trying to invoke that function using the string alone is there any way possible in doing so in C.

thanks
sandeep
Jan 10 '08 #1
2 1603
weaknessforcats
9,208 Expert Mod 8TB
Yes.

Expand|Select|Wrap|Line Numbers
  1. char fname[80]
  2. fgets(fname, 80, stdin);
  3. if (!strcmp("Howdy", fname)
  4. {
  5.       Howdy();
  6.  
  7. }
  8.  
But that only works if the function has no arguments. If the function has arguments, you will need to get those inside that if block.

But why would you do this?? Users don't care about function names, only programmers do.
Jan 10 '08 #2
Yes.

Expand|Select|Wrap|Line Numbers
  1. char fname[80]
  2. fgets(fname, 80, stdin);
  3. if (!strcmp("Howdy", fname)
  4. {
  5.       Howdy();
  6.  
  7. }
  8.  
But that only works if the function has no arguments. If the function has arguments, you will need to get those inside that if block.

But why would you do this?? Users don't care about function names, only programmers do.
Is there a way that i dont use an if block as in using the string name alone i should be able to invoke the function whose name is present in the string name

Psedocode:

gets(str);
invoke(str);


list of functions to execute:
func1();
func2();
.
.
.
my str will change dynamically as i will read a list of functions to executed from a file and execute them 1 after the other based on the str name using different threads.

Thanks
Sandeep
Jan 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
1
by: John Sidney-Woollett | last post by:
Is it possible to call a Postgres stored function (as if it were a procedure), using a PreparedStatement which will receive no return value, instead of having to use a CallableStatement and ignore...
11
by: Yahoo | last post by:
I have a programming issue where I need to know the whole history of the call stack to ensure it was never within a given method (specifically my own method). I am hooking into the XmlDocument...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
1
by: Michael | last post by:
Hi All, I've finally getting into .NET and have a question for you all. I'm creating an app that needs to insert user data into a word doc. One way I thought of doing this was to save the Word...
7
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
0
by: Robertson1995 | last post by:
I have been using Reflections for a while and I am familiar with macros, but am new to VBA. I need a VBA code that I think is fairly simple, but being new I need help. I have a piece of equipment...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.