问题
In case a system call function fails, we normally use perror to output the error message. I want to use fprintf to output the perror string. How can I do something like this:
fprintf(stderr, perror output string here);
回答1:
#include <errno.h>
fprintf(stderr, "%s\n", strerror(errno));
Note: strerror doesn't apply \n to the end of the message
来源:https://stackoverflow.com/questions/5483120/redirect-perror-output-to-fprintfstderr