>>>>>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!
>>>>>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 ); }
"I wish i could wish my wishs away"
"By indirections find directions out" -- William Shakespears
"Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"
Mizra -> love = Death...
RDB(Rocks yooo)..
http://www.cbeginnersunited.com
Are you ready for the Trix ???
Actually, you can doOriginally posted by datainjector
Code:(*f[ choice ])(choice);
f[choice]( choice );
You don't have to explicitly dereference