Using the freopen() library function
You can use the
freopen()
C library function to redirect C standard streams in all environments.
Parent topic:
Using C and C++ standard streams and redirection