Args to C progs??
Daniel Chan
chan at galaxy.ee.rochester.edu
Sun Mar 5 15:08:04 AEST 1989
>From: mitchemt at silver.bacs.indiana.edu
>Date: 4 Mar 89 22:57:00 GMT
>Organization: Indiana University CSCI, Bloomington
> 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;
>{
>......
> /* do something with arg1 here */
>.....
>}
>Unfortunately, the program doesn't seem to recognize arg1. If I pass it a
>string arg1 is just empty. Any help is appreciated. I just want to pass a
>string to the program.
> Thanks in advance,
> TM
Have you tried the following:
main (argc, argv)
int argc; /* total number of arguements including program name itself */
char *argv[]; /* an array of strings */
{
...
}
The command line arguments can then be accessed by argv[1], argv[2], ...,
argv[argc-1].
Hope that will work in Turbo C.
-dan.
More information about the Comp.lang.c
mailing list