You can simply use setbuf () to change the stderr buffer:
#include <stdio.h> int main(void) { char buf[BUFSIZ]; setbuf(stderr, buf); fprintf(stderr, "Hello, world!\n"); printf("%s", buf); return 0; }
prints:
Hello, world! Hello, world!
Note: you must change the buffer before any operation in the stream.
source share