invert(str) inverts the C string content and redirects it to util(a char pointer to some ready to use memory)
What can possibly cause it to work well when print(".") is uncommented?
There's nothing wrong with invert() or util, as the following code runs well:
The problem is that pos is uninitialized. Adding that call to print() makes the stars align right so that the memory that pos gets allocated to just happens to contain zero.
invert(str) inverts the C string content and redirects it to util
There's probably no need to do that. Just start at the end of str and fill it in going backwards. The print the string starting at whereever you end up.