What a mystery...
There's no mystery. This code:
dtostrf(temp, 2, 0, tempchar);
calls a function that has this signature:
char * dtostrf (double __val, signed char __width, unsigned char __prec, char *__s)
It converts a double, temp, to a string with a width of 2 and a precision of 0 to a string, and stores that string in the memory pointed to be tempchar.
The only question is what memory does tempchar point to? Lets look.
By default, the compiler initializes all global variables, like tempchar, to appropriate values. In the case of a pointer, the appropriate value is NULL.
So, what memory does it point to? None. It's a NULL pointer, and dtostrf is smart enough to know to do nothing with a NULL pointer.
On the other hand,
expects, apparently, for you to be smart enough to NOT pass it a NULL pointer.
Change tempchar's declaration to
and try again.
The difference here is that tempchar is still usable wherever a pointer is needed, but, it is not NULL and does point to writable memory.