On Saturday, 10 May 2014 at 20:24:50 UTC, MarisaLovesUsAll wrote:
Hi!
I sometimes got a useless messages in stdout from SDL_Image
library, and I want to temporary silence it. How do I do?
You can temporary redirect output to file. Example (on C):
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main ()
{
int stdout_copy = dup(STDOUT_FILENO);
close (STDOUT_FILENO);
int stdout_file = creat("myfile.txt", O_RDWR); //it obtains
the lowest free descriptor - 1, i.e. stdout.
printf("Hello file\n");
fflush(stdout); //don't forget to flush
close(stdout_file);
dup2(stdout_copy, STDOUT_FILENO);
printf("Hello console\n");
return 0;
}
But it's not very portable, you probably will need to write
something other for Windows system. And there are no checks for
errors in this example.
Also in SDL specific case it seems like it should redirect by
default - http://sdl.beuc.net/sdl.wiki/FAQ_Console but I don't
know whether it's true or not for SDL_Image.