Pass the result string as a parameter, so the responsibility for allocating it is with the caller. Eg. strcpy()
Make the array static, so the function reserves a fixed sized array. Eg. asctime().
The disadvantage of this is calling the same function twice trashes the previous result.
Allocate the string inside the function and return the newly allocated memory. The non-standard strdup() would be an example.
The disadvantage is that the caller has to know it was allocated, and then free it at some point.
--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.