Re: char** function parameters
- From: "John Bode" <john_bode@xxxxxxxxxxx>
- Date: 19 Jul 2005 13:47:53 -0700
confusedcoder@xxxxxxxxxxx wrote:
> The problem was that I was treating a char[256] as a char*. Here is a
> modification of Stephane's program to demonstrate what I want to do:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> void f(char **t)
> {
> printf("%s\n", *t);
> }
>
> int main(void)
> {
> char foo[256];
> strcpy(foo, "bar");
>
> f(&foo); /* WRONG */
>
Ah, enlightenment dawns. Try something like this:
char *p = foo;
f(&p);
> return EXIT_SUCCESS;
> }
>
> The gcc compiler warning is "assignment from incompatible pointer
> type," and what prints out when I run the program is garbage.
>
Yes, because the type of &foo is char(*)[256], not char**.
> So is it possible to pass the contents of foo[256] into the function
> f()?
Try the trick above, see if it helps.
.
- Follow-Ups:
- Re: char** function parameters
- From: Chris Torek
- Re: char** function parameters
- References:
- char** function parameters
- From: confusedcoder
- Re: char** function parameters
- From: Robert Gamble
- Re: char** function parameters
- From: confusedcoder
- char** function parameters
- Prev by Date: Re: fork problem
- Next by Date: Re: sprintf leading up to bus error (signal 10)
- Previous by thread: Re: char** function parameters
- Next by thread: Re: char** function parameters
- Index(es):
Relevant Pages
|