Re: The type of argv in K&R2
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Mon, 23 Jun 2008 11:02:41 +0000
Joe Wright said:
Richard Heathfield wrote:
candide said:Surely there are argc+1 members.
Hi,
K&R2 §5.10 tells that the second parameter to the main function,
usually called argv, has type pointer to character strings.
I don't think it says so in exactly those words (and if it does, I'd
argue that it's wrong). Certainly I can't find such wording on a cursory
look through that section.
Okay, here's the whole thing.
There exists an array of char *. Zero (or more, but exactly argc)
members of that array each point to the first character of a string that
represents a command line argument. The next member, the [argc] member,
is guaranteed to be NULL.
Right. Where did I say different?
Allow me to translate:
There exists an array of char *. Zero (or more, but exactly argc)
members of that array each point to the first character of a string that
represents a command line argument. The next member, the [argc] member,
is guaranteed to be NULL.
Get it now? :-)
Given argc == 2, argv[2] is the third
(and last) pointer in the array (and a NULL pointer).
Right. So exactly argc of them point to the first character of a string
that represents a command line argument (and I suppose I should clarify
that I am counting the program name - or some representation thereof - as
a command line argument), and the argv[argc]th member, argv[2] in your
example, is a null pointer. If that isn't broadly what I said the first
time, please point out the discrepancy.
<snip>
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.
- Follow-Ups:
- Re: The type of argv in K&R2
- From: Joe Wright
- Re: The type of argv in K&R2
- References:
- The type of argv in K&R2
- From: candide
- Re: The type of argv in K&R2
- From: Richard Heathfield
- Re: The type of argv in K&R2
- From: Joe Wright
- The type of argv in K&R2
- Prev by Date: Re: decrementing arrays
- Next by Date: Re: The type of argv in K&R2
- Previous by thread: Re: The type of argv in K&R2
- Next by thread: Re: The type of argv in K&R2
- Index(es):
Relevant Pages
|