Hi, i have a small problem i can't seem to figure out, although i remember the problem from previous code uh somewhere and i know it should be possible somehow :]

Anyway, lets say i have a struct looking like this:

struct foo {
int x;
char bar[20];
};

And a function to put data into the struct looking like this:

void foobar (struct foo **barf, int elements) {
int i;
for(i=0; i<elements; i++) {
barf[i]->x = 1;
strcpy(barf[i]->bar, "FooBar");
}
}


And a main function looking like this:

int main(void) {
struct foo *bar;
const int elements = 4;
bar = malloc(elements*sizeof(struct foo));
/* Now we should have a 4 elements array of struct foo */
/* And writing data to the struct in this function should be no problems but, calling foobar() to write the data causes a segfault. */
foobar(&bar, elemenrs);
free(bar);
}


I'm sure the answer is simple, and managing this should be possible somehow

Cheers