Using the freopen() library function

You can use the freopen() C library function to redirect C standard streams in all environments.