summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/switch.c
blob: 0e232dad49d92345d555954d55a54a28decc7cc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**************************************************************************
 *
 * Purpose: Program to demonstrate the 'switch/case' structure.
 * Method:  Prog looks at the number of parameters passed to it and 
 *          tells the user how many its got.
 * Author:  M J Leslie
 * Date:    09-Apr-94
 *
 **************************************************************************/

main(int argc, char *argv[])
{

  switch (argc)			/* Switch evaluates an expression (argc)  */
  {
				/* If expression resolves to 1, jump here */
  case 1:
    puts("Only the command was entered.");
    break;		        /* break - cases the execution to jump
				   out of the 'switch' block.             */
   
				/* If expression resolves to 2, jump here */
  case 2:
    puts("Command plus one parm entered");
    break;
   
				/* If expression resolves to 3, jump here */
  case 3:
    puts("Command plus two parm entered");
    break;

				/* Any other value jumps here.            */
  default:
    printf("Command plus %d parms entered\n", argc-1);
    break;
  }
}