Redirect perror output to fprintf(stderr, “ ”)

青春壹個敷衍的年華 提交于 2019-11-30 14:33:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!