RE: Re: What does "*" mean in "int main(int argc, char *argv[])"?

From: Tom (tvaus_at_sympatico.ca)
Date: 02/15/05


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



Relevant Pages

  • Re: Function Problem
    ... > but fnReplace takes pointers to strings of length 16. ... > void fnReplace (char *RplStr) ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: char vs int
    ... 'a' is a character constant. ... A variable of type char can ... of them instead of int arrays. ... concept of pointers. ...
    (comp.lang.c)
  • =?windows-1252?Q?C_Programming-_Begginners_to_Intermediate-_July_12th_to_15,2011?=
    ... Control Statements – II ...Single dimensional arrays ... • Arrays and pointers ...Representing strings ...
    (Debian-User)
  • Re: simple question regarding 5.5 of Ritchie & Kernighan
    ... pointers to char and arrays of char: ... a memory address to hold the value it points to and that memory address ... runtime) multidimensional arrays. ... arrays of pointers to arrays, ...
    (comp.lang.c)
  • Re: Can C do it ?
    ... Strings and arrays *are* pointers in C. ... If you intend to use strings and arrays, you must use pointers. ... /* this typedef makes mot into a type which can hold ...
    (comp.lang.c)