RE: Re: What does "*" mean in "int main(int argc, char *argv[])"?
From: Tom (tvaus_at_sympatico.ca)
Date: 02/15/05
- Next message: Vince Morgan: "Class default initialiation"
- Previous message: Mike Wahler: "Re: parsing error?"
- In reply to: Francis Glassborow: "Re: What does "*" mean in "int main(int argc, char *argv[])"?"
- Next in thread: Barry Schwarz: "Re: What does "*" mean in "int main(int argc, char *argv[])"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 14 Feb 2005 23:26:31 -0500
I stand corrected by your reply.
argv[] entries are pointers to arrays of null terminated
char arrays (strings). Access would be as follows in a loop
using argc for the number of parameters:
argv[0] program name
argv[1] first parameter
argv[2] second parameter
etc.
It has been quite a few years since I wrote DOS programs
that processed the command line. I guess old age is creeping
up on me and I forgot . . .
I did a "brain refresh" and looked at some of the code I wrote
years ago. "char *argv[]" says it all as you stated.
Tom.
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:QQnbq6I+S0DCFwoC@robinton.demon.co.uk...
> In article <TsGPd.9$cp2.1628@news20.bellglobal.com>, Tom
> <tvaus@sympatico.ca> writes
> >argc - is the number of parameters in the command line including
> >the program name.
> Yes
> >argv[] - is the array of parameters passed in the command line.
> No it isn't. It is a pointer to an array of pointers to nul-terminated
> arrays of char (i.e. what C uses for strings)
>
> >
> >As JoeC said, it is a pointer to an array of type char.
>
> He didn't
> >You can use argc in a for loop to process the argv[] values.
> Indeed you can but only if you understand what argv[0] etc. actually
> are.
>
> >
> >The int main simply means that the program will return an int after
> >execution. Using 'void main . . .' will work as well, you just don't
> >have to return a value. (not good if you want to use your program
> >in a batch file and need to check the error level for taking care of
> >the problem the program encountered)
>
> No. void main . . . may work with a compiler that supports that as an
> extension but neither C nor C++ requires that it is supported and
> strictly speaking once you write that you are outside the guarantees
> provided by whichever language you are using.
>
>
> --
> Francis Glassborow ACCU
> Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
> For project ideas and contributions:
http://www.spellen.org/youcandoit/projects
- Next message: Vince Morgan: "Class default initialiation"
- Previous message: Mike Wahler: "Re: parsing error?"
- In reply to: Francis Glassborow: "Re: What does "*" mean in "int main(int argc, char *argv[])"?"
- Next in thread: Barry Schwarz: "Re: What does "*" mean in "int main(int argc, char *argv[])"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|