473,396 Members | 1,706 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,396 software developers and data experts.

Reg Fucntion pointers

3
Hi All,

I'm learning Pointers to functions in C.But I have some doubts regardign the same.I would be v.happy and thankful if somebody can help me out on my pbm
The problem is mentioned below:
------------------------------------------
Consider I have 5 different functions which returns different type and takes different arguements also.
Eg :
int aaa(int x);
void bbb(int x,int y, int z);
void ccc(void);
void ddd(char *x,char *y,char *z);
void eee(UINT8 x);

And these are all some operations when the user presses some commands,
Eg:
Commands = "command1","command2","command3","command4","comma nd5"

How will i use the fucntion pointers to execute the corresponding function with their arguements?

If possible, if somebody can reply to me ASAP.

Thanks in advance,
Sowmi
Jun 22 '07 #1
2 1238
askcq
63
i didnt get "pressing commands "
can u explain it little more clearly
Jun 22 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
int aaa(int x);
void bbb(int x,int y, int z);
void ccc(void);
void ddd(char *x,char *y,char *z);
void eee(UINT8 x);
These functions will need different function pointers.
Expand|Select|Wrap|Line Numbers
  1. int aaa(int x);\
  2.  
will need a function pointer:
Expand|Select|Wrap|Line Numbers
  1. int (*fp)(int);
  2.  
You assign the address of the functtion to the pointer:
Expand|Select|Wrap|Line Numbers
  1. fp = aaa;
  2.  
and then you can call the function using the pointer:
Expand|Select|Wrap|Line Numbers
  1. fp(20);
  2.  
But you need a diffrerent function pointer for:
Expand|Select|Wrap|Line Numbers
  1. void bbb(int x,int y, int z);
  2.  
  3. void (*fp1)(int, int, int);
  4.  
  5. fp1 = bbb;
  6.  
  7. fp1(10,20,30);
  8.  
Your example is not a case where you use function pointers. Function pointers are used where you have many functions with the same arguments and the same return type. Then you can choose which function to call by putting its address in a function pointer. The pointer can be passed to another function so that the other function can call different functions. This is commonly done with sorts where you pass the address of the compare function to the sort so you can sort in different sequences.
Jun 22 '07 #3

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

Similar topics

27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
3
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL,...
9
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar...
5
by: ra294 | last post by:
When I use the Now() Fucntion i my ASP.net application I get a date format of mm/dd/yy. I want it to be dd/mm/yy. I set in the web config "culture="en-GB" uiCulture="en" and also set the regional...
12
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
1
by: Haggr via AccessMonster.com | last post by:
"My Fucntion()" will return a string value of lxb114 for a query field with a string of xlb114r. So my question is how to text that Function in the immediate window of the module? Tried...
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.