This is... a pointer and memory problem. Which is something you'll learn much more about in future weeks. Essentially the problem is this: each function has a portion of memory that it uses for local variables, including your:
outstr vars. This memory is called a local stack frame. When the function is done executing, the program assumes this memory is no longer needed, and the next function call will overwrite its contents with its own local variables.
The confusion comes from the fact that a variable of type
string does not actually contain a string, but a pointer to a memory location that contains a sequence of characters (and a NULL character). Your return value is a pointer into the stack frame that no longer exists. Once you call
printf, that function starts overwriting that memory with its own variables. Your results will likely be garbage.
The solution you will eventually use is to create a character buffer in the
main function and pass its address to your function, so that your string is stored in
main's stack frame and not your function's stack frame. Another solution is dynamic memory allocation. Both of these are described more in depth later in the class.
For now, you might just want to move all of your code into the
main function. After the lessons on pointers, come back and reimplement this function with what you've learned.