diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/EXAMPLES/command_line.c |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/EXAMPLES/command_line.c')
-rw-r--r-- | reference/C/EXAMPLES/command_line.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/reference/C/EXAMPLES/command_line.c b/reference/C/EXAMPLES/command_line.c new file mode 100644 index 0000000..40135cb --- /dev/null +++ b/reference/C/EXAMPLES/command_line.c @@ -0,0 +1,43 @@ +/******************************************************************** + * + * Purpose: Demonstrate getting parameters from the command line. + * Author: M J Leslie + * Date: 27-Mar-94 + * + ********************************************************************/ + +#include <stdio.h> + +main(int argc, char *argv[]) +{ + int count; + + /* Main takes two variables 'argc' is the number of parms on the + * command line and 'argv' is a pointer to each of the parameters. + * + * int argc -- integer number called 'argc' + * char *argv[] -- Character pointer array! + */ + + printf("%i parameters entered on the command line.\n", argc); + + /* + * progname argc = 1 + * progname parm1 parm2 argc = 3 + */ + + /* + * We take 1 from argc because + * the argv array starts at zero + * an ends at argc -1 + */ + + for ( count = 0; count <= argc -1 ; count++) + { + /* printf expects a pointer + * to the text + */ + + printf("parm %d is %s\n", count, argv[count]); + } +} |