重定向PERROR输出fprintf中(标准错误,"") [英] Redirect perror output to fprintf(stderr, " ")

查看:345
本文介绍了重定向PERROR输出fprintf中(标准错误,"")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果万一系统调用函数失败,我们通常使用PERROR输出错误信息。我想用fprintf中输出PERROR字符串。我该怎么做?

请帮忙,

先谢谢了。

事情是这样的:

  fprintf中(标准错误,PERROR输出字符串这里);


解决方案

 的#include<&errno.h中GT;fprintf中(标准错误,%S \\ n字符串错误(错误));

请注意:字符串错误不适用 \\ n 来的邮件的末尾

If in case a system call function fails, we normally use perror to output the error message. I want to use fprintf to output perror string. How can i do that?

Please help,

Thanks in advance.

Something like this:

fprintf(stderr, perror output string here);

解决方案

#include <errno.h>

fprintf(stderr, "%s\n", strerror(errno));

Note: strerror doesn't apply \n to the end of the message

这篇关于重定向PERROR输出fprintf中(标准错误,&QUOT;&QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆