Mail Archives: djgpp/1998/12/18/12:55:22
Marcus Rohrmoser wrote:
> Define main as
> `int main(int argc, char** argv)`
Technically, the prototype has char *argv[] (though the name of the
variable doesn't matter since it's local), but since arrays
automatically decay to pointers in function parameters, it doesn't make
much difference.
> and you`ll have the number of arguments in `argc` and the values in
> argv[1] to argv[argc]. argv[argc+1] is NULL by definition. argv[0] is
> the program`s name.
argv is a zero-based, C array just like anything else. argc gives the
total number of elements in the array, which is the number of arguments
to the program plus one (for the program name itself). argv[0] is the
program name, argv[1] is the first argument, argv[2] is the second
argument, etc., argv[argc - 1] is the last argument, and argv[argc] is
the null pointer. argv[argc + 1] is undefined and will likely crash.
--
Erik Max Francis / email max AT alcyone DOT com / whois mf303 / icq 16063900
Alcyone Systems / irc maxxon (efnet) / finger max AT finger DOT alcyone DOT com
San Jose, CA / languages En, Eo / web http://www.alcyone.com/max/
USA / icbm 37 20 07 N 121 53 38 W / &tSftDotIotE
\
/ Wars may be fought with weapons, but they are won by men.
/ Gen. George S. Patton
- Raw text -