You are returning a pointer to local variables. This doesn't work and will be raised by your compiler in the warnings.
Allocated data and return a unique pointer, or just simply use a string, as you are passing memory management to the caller. You are in C++, use C++ style code, not C (printf
and others).