Re: Command line arguments
From: Richard Bos (rlb_at_hoekstra-uitgeverij.nl)
Date: 03/09/04
- Next message: Kevin Torr: "md5.h file"
- Previous message: Richard Bos: "Re: How to print ^M (ctrl M)"
- In reply to: Irrwahn Grausewitz: "Re: Command line arguments"
- Next in thread: Mike Wahler: "Re: Command line arguments"
- Reply: Mike Wahler: "Re: Command line arguments"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Mar 2004 10:56:13 GMT
Irrwahn Grausewitz <irrwahn33@freenet.de> wrote:
[ Slightly condensed... ]
> The following program prints all given command line arguments:
>
> #include <stdio.h>
>
> int main( int argc, char *argv[] ) /* [1] */
> {
> int i;
>
> for ( i = 0; i < argc; i++ )
> puts( argv[ i ] );
> return 0;
> }
>
> Notes:
> 1. argc holds the number of arguments
> 2. argc is guaranteed to be non-negative
> 3. argv is an array of pointers to strings holding
> the actual arguments (if argc > 0)
> 4. argv[ argc ] is guaranteed to equal NULL
> 5. if argc > 0, argv[ 0 ] may contain (part of) the path of
> the executable, or an empty string, depending on the
> implementation.
6. If your OS cannot give you both upper- and lower-case strings, you're
guaranteed to get them in lower case.
7. argc and argv, being normal function arguments, can be modified (but
then, of course, don't correspond to the CLA you gave); the pointer
members of argv can _not_ be portably written to; but the character
strings these pointers point to are, again, writable. I.e., argv=x
is legal; argv[1]=x is not; but argv[1][1]=x is, providing that
argv[1][1] does exist. Odd, but true.
Richard
- Next message: Kevin Torr: "md5.h file"
- Previous message: Richard Bos: "Re: How to print ^M (ctrl M)"
- In reply to: Irrwahn Grausewitz: "Re: Command line arguments"
- Next in thread: Mike Wahler: "Re: Command line arguments"
- Reply: Mike Wahler: "Re: Command line arguments"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|