fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int update(void);
  5. int upgrade(void);
  6. int quit(void);
  7. void show(const char *question, const char **options, int (**actions)(void), int length);
  8.  
  9. int main(void){
  10. const char *question = "Choose Menu\n";
  11. const char *options[3] = {"Update", "Upgrade", "Quit"};
  12. int (*actions[3])(void) = {update,upgrade,quit};
  13.  
  14. show(question,options,actions,3);
  15. return 0;
  16. }
  17.  
  18. int update(void){
  19. printf("\n\tUpdating...\n");
  20. return 1;
  21. }
  22.  
  23. int upgrade(void){
  24. printf("\n\tUpgrade...\n");
  25. return 1;
  26. }
  27.  
  28. int quit(void){
  29. printf("\n\tQuit...\n");
  30. return 0;
  31. }
  32.  
  33. void show(const char *question, const char **options, int (**actions)(void), int length){
  34. int choose = 0, repeat = 1;
  35. int (*act)(void);
  36.  
  37. do{
  38. printf("\n\t %s \n",question);
  39. for(int i=0;i<length;i++){
  40. printf("%d. %s\n",(i+1),options[i]);
  41. }
  42.  
  43. printf("\nPlease choose an Option: ");
  44. if((scanf("%d",&choose)) != 1){
  45. printf("Error\n");
  46. }
  47. act = actions[choose-1];
  48. repeat = act();
  49.  
  50. if(act==0){
  51. repeat = 0;
  52. }
  53. }while(repeat == 1);
  54. }
Runtime error #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
Standard output is empty