1  /* menuc.c - 2011-03-23
 2  This little program is a basic structure to create a menu in C for use
 3  as a launcher functions or programs.
 4  Update: http://myc01.free.fr/menuc
 5  
 6  License: Public Domain Dedication (CC0 1.0)
 7    http://creativecommons.org/publicdomain/zero/1.0/
 8  
 9  Usage: menuc.exe [program_number]
10  */
11  
12  /*
13  To display the accented characters, change the font of the console :
14    DOS console : Menu / Properties / font = "Lucida Console".
15  */
16  
17  #include <stdio.h>
18  #include <stdlib.h>
19  
20  void program_1 (void)
21  {
22    printf ("\nProgram 1 : 'Title of program 1'.\n");
23    system ("if exist program_1.bat program_1.bat");
24  }  /* program_1 */
25  
26  void program_2 (void)
27  {
28    printf ("\nProgram 2 : 'Title of program 2'.\n");
29    /* ... */
30  }  /* program_2 */
31  
32  void program_3 (void)
33  {
34    printf ("\nProgram 3 : 'Title of program 3'.\n");
35    /* ... */
36  }  /* program_3 */
37  
38  int run_program (int prog_n)
39  {
40    switch (prog_n)
41    {
42      case 1:
43        program_1 (); break;  /* Start function 'program_1' */
44      case 2:
45        program_2 (); break;
46      case 3:
47        program_3 (); break;
48      default:
49        return 0;
50    }  /* switch */
51  
52    return prog_n;
53  }  /* run_program */
54  
55  int main (int argc, char *argv[])
56  {
57    int i, prog_n;
58  
59    /* Change the code page :
60       windows-1252 = ANSI Latin 1; Western European (Windows) */
61    /* system ("chcp.com 1252 >NUL"); */
62  
63    if (argc > 1)
64      if (sscanf (argv[1], "%d", &prog_n) == 1)
65        return run_program (prog_n);
66  
67    while (1)  /* Infinite loop */
68    {
69      system ("cls");
70      printf ("Main menu :\n\n");
71      printf ("0: Exit program.\n");
72      printf ("1: Program 1.\n");
73      printf ("2: Program 2.\n");
74      printf ("3: Program 3.\n");
75  
76      printf ("\nEnter the number of the program to run : ");
77      scanf ("%d", &prog_n);
78      while ((i = getchar ()) != '\n' && i != EOF);  /* fflush (stdin); */
79  
80      if (run_program (prog_n) == 0)
81        return 0;
82  
83      getchar ();
84      /* system ("pause"); */
85    }  /* while */
86  
87  }  /* main */