Args to C progs??

Ex-God c08_d103 at jhunix.HCF.JHU.EDU
Mon Mar 6 11:08:33 AEST 1989


In article <9600003 at silver> mitchemt at silver.bacs.indiana.edu writes:
>
>     I am writing a program in Turbo C and would like to know how to pass
>arguments to it from the command line after it is compiled to a .exe file.
>
>I have tried:
>
>main(arg1)
>char *arg1;

     Well, I don't know Turbo C, but if it's reasonably standard, it
should pass an integer and an array of strings.  Try

main (argc, argv)
int argc;
char *argv[]

Then argv[0] will hold the command name, argv[1] will hold the first
argument, etc.  As far as I know, there's no definition for what makes
an argument, but in Unix, it's a word separated by white space.  Oh,
argc will hold the number of arguments (including the command name).

For more information, check K&R1 5.11 (p110-114) or K&R2 5.10
(p114-118).  If someone knows Turbo C better than I do, tell me if
that will work....

     -- Andrew Barnert (Andy Social/Andy Christ/Andy Matter/ex-God)
        ins_balb at jhunix/ins_balb at jhuvms/c08_d103 at jhunix
The opinions expressed in this message are yours.
"If you can't stand the Big Chill, burn down the freezer." -- Jello Biafra



More information about the Comp.lang.c mailing list