>>>>>you can just use an array of function pointers and use the number input by the user as the index in the array<<<
Can you give an example of this?
Thanks!
Printable View
>>>>>you can just use an array of function pointers and use the number input by the user as the index in the array<<<
Can you give an example of this?
Thanks!
This ia an example for array of pointer to a function.A question forCode:#include <stdio.h>
#include <stdlib.h>
void func1( int);
void func2( int );
int main()
{
void (*f[2])(int) = { func1, func2 };
int choice;
printf("Enter an input:");
scanf("%d", &choice );
(*f[ choice ])(choice);
system("PAUSE");
return 0;
}
void func1( int num)
{
printf("you entered %d.So function 1 was called\n", num);
}
void func2( int num)
{
printf("You enterd %d.SO function2 was vcalled", num );
}
Actually, you can doQuote:
Originally posted by datainjector
Code:(*f[ choice ])(choice);
f[choice]( choice );
You don't have to explicitly dereference