BL> Are you saying that strcpy(names[x], line); will work?? How can it?
BL> names[][] is a two dimensional array. I'll try it...
BL> ... [later]
BL> It *does* work. How?
It works by definition.
BL> It must mean that a 2-dimensional array is really a one-dimensional
BL> array of strings. What happens with a 3-dimensional array? If I had
BL> names[x][y][z] can I put names[x] to address the [y][z] array? and
BL> names[x][y] to address the z string? Whatta great idea!
Yes, all this is true. By definition.
BL> Another thing I don't quite understand is your use of things like
BL> char **whatever;
BL> You use it quite a bit.
BL> Does this mean it's a pointer to a pointer to a character? What's
Yes.
BL> the point of that? It's the same size, so what does the extra code
BL> gain? Why not just use the original pointer?
Well, say you wrote a function, and you want to set a pointer, as such:
/* determine who is the best person */
void brilliant_function(char **p)
{
static char names[3][20] = { "bob", "rod", "paul");
*p = names[2];
return;
}
int main(void)
{
char *n;
brilliant_function(&n);
printf("the brilliant person is %s\n", n);
return (0);
}
Well, as you can see, the caller is only declaring a pointer himself. That
pointer is pointing to some random location in memory. If he were to pass
that pointer directly to the function, then the function would receive a
pointer to a random location in memory, which is of absolutely no use to
anyone. This way, the function receives the address of where the
"4-byte" pointer ITSELF is stored, so that it can CHANGE the
pointer, so that instead of pointing to a random location, it points to the
name of a brilliant person. BFN. Paul.
@EOT:
---
* Origin: X (3:711/934.9)
|