use fwrite to write to stdout and stderr