fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef void (*FNTYPE)(void);
  5. FNTYPE fn_arr[5];
  6.  
  7. void fun1(void){
  8. printf("\n I'm func 1 \n");
  9. }
  10.  
  11. void fun2(void){
  12. printf("\n I'm func 2 \n");
  13. }
  14.  
  15.  
  16.  
  17.  
  18. int decidefunc(char* inp){
  19. if(inp == NULL){
  20. return 0;
  21. }
  22. else if(*inp == 'a'){
  23. return 1;
  24. }
  25. else if(*inp == 'b'){
  26. return 0;
  27. }
  28. else if(*inp == 'c'){
  29. return 1;
  30. }
  31. else{
  32. return 0;
  33. }
  34. }
  35.  
  36. void callMyFunc(char* inp){
  37. printf("\n %s \n",__func__);
  38. int idx = decidefunc(inp);
  39. fn_arr[idx]();
  40. }
  41.  
  42. void do_lengthy_op(char* inp,void (*call)(char *inp)){
  43. printf("\n do_lengthy_operation! \n");
  44. call(inp);
  45. }
  46.  
  47. int main(){
  48. fn_arr[0] = &fun1;
  49. fn_arr[1] = &fun2;
  50.  
  51. do_lengthy_op("b",callMyFunc);
  52. return 0;
  53. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
 do_lengthy_operation! 

 callMyFunc 

 I'm func 1