2022-06-24 02:43:47 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2022-07-25 15:10:48 +00:00
|
|
|
#include <stdlib.h>
|
2022-07-24 09:31:35 +00:00
|
|
|
|
2022-07-23 21:58:09 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
2022-07-25 15:10:48 +00:00
|
|
|
puts("stdout is printed to console");
|
|
|
|
if (freopen("redir.txt", "w", stdout) == NULL)
|
|
|
|
{
|
|
|
|
perror("freopen() failed");
|
|
|
|
return EXIT_FAILURE;
|
2022-07-24 09:31:35 +00:00
|
|
|
}
|
2022-07-25 15:10:48 +00:00
|
|
|
puts("stdout is redirected to a file"); // this is written to redir.txt
|
|
|
|
fclose(stdout);
|
|
|
|
return EXIT_SUCCESS;
|
2022-06-24 02:43:47 +00:00
|
|
|
}
|