From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/EXAMPLES/switch.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 reference/C/EXAMPLES/switch.c (limited to 'reference/C/EXAMPLES/switch.c') diff --git a/reference/C/EXAMPLES/switch.c b/reference/C/EXAMPLES/switch.c new file mode 100644 index 0000000..0e232da --- /dev/null +++ b/reference/C/EXAMPLES/switch.c @@ -0,0 +1,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; + } +} -- cgit v1.2.3-54-g00ecf