www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/18/12:55:22

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Accessing command line from within DJGPP
Date: Fri, 18 Dec 1998 09:49:29 -0800
Organization: Alcyone Systems
Lines: 29
Message-ID: <367A95A9.33789E52@alcyone.com>
References: <3673ba32 DOT 756202 AT news DOT shineline DOT it> <367A3863 DOT 5658564 AT lrz-muenchen DOT de>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
X-Mailer: Mozilla 3.01 (X11; I; Linux 2.0.34 i686)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019