如何找到fprintf()的实际错误
How to find the fprintf() actual error?
在我的程序中,fprintf()
返回-1,表示错误。我怎样才能知道实际的错误是什么?
#include <errno.h>
#include <string.h>
...
rc = fprintf(...)
if (rc < 0)
printf("errno=%d, err_msg="%s"n", errno,strerror(errno))
需要查看"errno
"的值。大多数库函数将其设置为特定的错误代码,您可以在errno.h
中查找它,也可以使用perror
或strerror
来获得用户可读的版本。
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main (void) {
FILE *fh = fopen ("junk", "w");
if (fh != NULL) {
if (fprintf (fh, "%s", "hello") < 0)
fprintf (stderr, "err=%d: %sn", errno, strerror (errno));
fclose (fh);
}
return 0;
}
相关文章:
- 配置:错误:找不到 MySQL 包含目录
- C ++程序编译错误,找不到/访问文件
- Visual Studio 2013,错误 MSB8020:找不到 Visual Studio 2010 的生成工具
- 致命错误:找不到'boost/uuid/uuid.hpp'文件
- pip install uwsgi 失败,出现 /usr/local/include/string/string.h:7:10:致命错误:找不到'sstream'文件?
- SFML 库未加载错误,找不到图像
- 链接错误 CXX:找不到 -lvulkan
- 致命错误:找不到 SFML/System.hpp' 文件
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- 错误:找不到数字文字运算符"运算符 " " U"?
- C++生成致命错误:找不到'numpy/arrayobject.h'文件
- 配置:错误:*** -LM找不到!**
- 编译时得到错误:找不到'QtGui/QAction'文件 #include < QtGui/QAction>
- 分段错误,找不到我做错的地方
- Qt debian/ubuntu:无法编译,错误:找不到 -lGL
- c++链接错误,找不到全局.h结构
- clang++:致命错误:找不到'unistd.h'文件
- 在 OS X 上编译lsd_slam会引发链接错误 ld:找不到 -lGL 的库
- 致命错误:找不到'stdarg.h'文件
- 添加指针导致类错误,找不到重载的成员函数