Re: char** function parameters





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.

.



Relevant Pages