It's been a while since I've coded C, and I'm just getting used to it again. I am having a problem with a double pointer, as in a pointer that points to a list of other character pointers. My problem is that I don't understand why I can declare this double pointer in main() but not in a function:
----------------------------
main () {
char **dirnames;
dirnames[0] = "/usr/local/share";
dirnames[1] = "/usr/local/www";
}
-----------------------------
This section of code works just fine. The following section of code does NOT work though:
------------------------------
main () {
test ("/usr/local/share");
}
int test (char *path) {
char **dirnames;
dirnames[0] = path;
dirnames[1] = "/usr/local/www";
}
--------------------------------
This section of code gives "Bus error" or segfaults, one of the two. I assume it is just a syntax problem, but if my environment information is needed, I can provide it.
Thanks for any help.