Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass a function as a parameter?

Status
Not open for further replies.

subra

Programmer
Aug 6, 2000
45
IN
is it possible to do this?
I work on DOS and i use turbo-c.

i have a function say

void abc(void);

i have a second function say

void xyz( p1, p2, ..);
{

abc();

}
my question is, how can i pass the function abc as a parameter to the function xyz. is it possible to do this?

more specifically, xyz is a function to which i pass four parameters. 1. database name, 2. index name, 3. index key, 4. index mode. THe index key has to be calculated for each record so that function xyz adds the key at the appropriate place in the index file. If i simply call the function abc() from within the function xyz, everything works fine. but then function xyz is tied to abc. if i have to use a different key, i have to write a new function, the only difference being the function abc(). if i can pass the function as a parameter the function xyz could be more generic.

any c guru could please help. thanks

subra if you find this useful let me know at vksubra@icenet.net
 
you can use function pointers ....

void abc(void);
void ezc(void);

void xyz( p1, p2, void (*pFunc)(void)) {
pFunc;
}

int main(void) {
xyz(p1,p2,abc);
xyz(p1,p2,ezc);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top