Re: char** function parameters
- From: "Brendan" <bed88012@xxxxxxxxxx>
- Date: Thu, 11 Aug 2005 20:29:43 -0000
> Suppose I have the following function:
>
> void doSomething(char** array, int size);
>
> Normally, I would call the function with an array of, say, 3
> elements...
>
> char* strs[] = { "str1","str2","str3" };
> doSomething(strs, 3);
what this declaring is a pointer to an arrray. an array in memory is a
pointer to the data(i.e pointer to a pointer). The doSomething is asking for
a ponter to a pointer. which is way this one works
>
> That works fine. But if I want to pass it only one string, I would
> think this would work....
>
> char* str = "str1";
> doSomething(&str, 1);
while this declares a pointer to the data, doSomething is expecting a
pointer to a pointer and so it is treating "Str1" as the memory adress (i.e.
it is going to goto to adress 0x53747231) which is not where the string is.
>
> It compiles with a warning about incompatible pointer types, and
> needless to say it doesn't behave as I expected. "str1" does not get
> passed into the function. What am I doing wrong? Or is it simply not
> possible to pass a single char* into this function?
--
comp.lang.c.moderated - moderation address: clcm@xxxxxxxxxxxx -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
.
- Follow-Ups:
- Re: char** function parameters
- From: Barry Schwarz
- Re: char** function parameters
- Prev by Date: Re: return() value
- Next by Date: Re: switching on strings in standard C
- Previous by thread: return() value
- Next by thread: Re: char** function parameters
- Index(es):
Relevant Pages
|