Why does this work:
//split returns (char**)
char *temp2;
temp2=split(array[i],'=')[1];
and this doesn't:
char **temps;
temps[0]=temp2; //crashes
or this:
temps[0]=split(array[i],'=')[1]; //crashes
Why does this work:
//split returns (char**)
char *temp2;
temp2=split(array[i],'=')[1];
and this doesn't:
char **temps;
temps[0]=temp2; //crashes
or this:
temps[0]=split(array[i],'=')[1]; //crashes
temps is just a pointer to a char*, but it has no initalized, sensible value! temps[0] is equivalent to *(temps + 0), but you cannot dereference a garbage value -- you first have to make temps points somewhere useful, e.g. by allocating memory for it.
If you want to store some char*s with automatic storage, then declare an array of char pointers instead:
char * temps[20];
temps[0] = /*... etc. ...*/
Split returns a pointer to a pointer to a char. So, what is returned from split(array[i],'=')[1] is a pointer to char which is what you declared on the stack and thus reserved space for it. That is why it works.
The other two don't work because the space pointed to is not allocated. You should use malloc().
Think of it this way:
char *temp2 = "foo";
char **temps;
temps[0] = temp2; // won't work
temps = &temp2; // ok
temp2 points at a C string. You can point temps at the address of temp2, (&temp2) but you can't dereference temps (that is, temps[0]) unless you first make it point at something valid. From your question it sounds like you want to malloc() an array of char* first.
In the second and third cases, you are dereferencing temps[0] without first making it refer to some valid memory location. As has been pointed out, temps is pointing at a garbage location.
Your first case works because you're dereferencing split(), so it's giving you a char*.