Re: how to write a program that takes arguments from commandline?



Keith Thompson wrote:
Martin Jørgensen <unoder.spam@xxxxxxxxxxxx> writes:

stathis gotsis wrote:
-snip-


Maybe this is relevant:
http://c-faq.com/misc/argv.html

Thanks. That looks exactly like the place to start. Also thanks to the
other answers. I assume argc contains the number of (space-separated)
arguments.


The arguments aren't necessarily space-separated; that depends on the
mechanism (for example, a shell) used to invoke your program.

If the arguments isn't space-separated, how else would they be separated?

argc is the number of valid elements of the array pointed to by argv.
If you invoke your program with 2 command-line arguments, argc will be 3.
argv[0] probably points to (some form of) the name of your program;
argv[1] and argv[2] point to your command-line arguments.

Just as I thought.


Med venlig hilsen / Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
.



Relevant Pages

  • Re: how to write a program that takes arguments from commandline?
    ... I assume argc contains the number of ... programs are often invoked from a shell ... Shells *can* use spaces to delimit arguments, ... like for constructing the arguments for the programs you invoke. ...
    (comp.lang.c)
  • Re: wildcards in argv
    ... The *shell* is where wildcard are handled, rather than forcing ... If you invoke your program as "foo *.c", ... If there are are 50 files that match, argc will be 51 and each ... of those files will be named in one of the argv array of ...
    (comp.unix.programmer)
  • Re: Tcl crashes and/or hangs in RHEL5?
    ... Compile it into "Invoke", then copy that to "/home/Fred/mydeamon" and name your Tcl code as "/home/Fred/mydeamon.tcl". ... int Tcl_AppInit3{ ... int main(int argc, char * argv) { ...
    (comp.lang.tcl)
  • Re: how to write a program that takes arguments from commandline?
    ... argc is the number of valid elements of the array pointed to by argv. ... If you invoke your program with 2 command-line arguments, ... Keith Thompson kst-u@xxxxxxx ...
    (comp.lang.c)
  • Re: algorithm by eratosthenos
    ... #> The usual names for the parameters to main are argc and argv. ... #> and P is obfuscation. ...
    (comp.lang.c)