Message-Id: <199807042347.AAA32125@sable.ox.ac.uk> Comments: Authenticated sender is From: George Foot To: Theo Landgraf Date: Sun, 5 Jul 1998 00:41:43 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: handle commandline arguments. Reply-to: george DOT foot AT merton DOT oxford DOT ac DOT uk CC: djgpp AT delorie DOT com Precedence: bulk On 19 Jun 98 at 10:04, Theo Landgraf wrote: > how do i handle the command line options in my source. > > in Borland C3.1 i use simpel _argv[0] for the programname. > how do i do this in djgpp? The `main' function accepts two parameters, normally called `argc' and `argv', as follows: int main (int argc, char *argv[]) `argc' is the number of words on the command line (including the program's name), and `argv' is an array of pointers to the individual words, which is also terminated by a NULL pointer. I suspect that Borland defines `_argc' and `_argv' to be global variables equivalent to `argc' and `argv' in `main'. DJGPP also has similar global variables which are defined in `crt0.h' -- they're called `__crt0_argc' and `__crt0_argv'. So, either use the standard way (i.e. arguments passed to the `main' function), or use `__crt0_argc' and `__crt0_argv' (after #include ). You can mirror the arguments of `main' to globals yourself if you like: | int _argc; | char **_argv; | | int main (int argc, char *argv[]) | { | _argc = argc; | _argv = argv; | ... and then use `_argc' and `_argv' elsewhere in the program. This is more portable than using djgpp's `__crt0_*' variables. Note that djgpp automatically performs Unix shell-like globbing of command line arguments -- wildcarded arguments are expanded into lists of existing files which match the wildcarded arguments. You can turn this off if you like; see the djgpp FAQ, section 16.2. -- george DOT foot AT merton DOT oxford DOT ac DOT uk