Quick/Hacky answer(?):
Make
char type[sz];
into
static char type[sz];
Long answer: The error is pretty clear, you are returning the address of a variable that is going to be destroyed soon as the function returns. There are a couple of ways to get around this.
One easy way is to make type static
, this would fix things, by making the type variable have a lifetime of the program, but this will mean that you cannot call it twice in a row, you need to print or copy the result before calling again.
The other way, is to allocate memory for a char
array within your function and hope that you remember to free
it once you are done with it. If you don't you will have a memory leak. This does not suffer from the above disadvantage.