小白教程
所有教程
关于
Search
172.69.59.161
172.69.59.161
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“C macro errno”的源代码
本页内容
下一节:
C_macro_edom
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:extern int errno}}[[Category:c standard library errno h|1]] = C 库宏 - errno = [[c standard library errno h|C 标准库 - <errno.h>]] == 描述 == C 库宏 '''extern int errno''' 是通过系统调用设置的,在错误事件中的某些库函数表明了什么发生了错误。 == 声明 == 下面是 errno 宏的声明。 <pre> extern int errno </pre> == 参数 == * '''NA''' == 返回值 == * '''NA''' 下面的实例演示了 errno 宏的用法。 <sample title="" desc="" lang="c" hererun="1"> #include <stdio.h> #include <errno.h> #include <string.h> extern int errno ; int main () { FILE *fp; fp = fopen("file.txt", "r"); if( fp == NULL ) { fprintf(stderr, "Value of errno: %d\n", errno); fprintf(stderr, "Error opening file: %s\n", strerror(errno)); } else { fclose(fp); } return(0); } </sample> 让我们编译并运行上面的程序,当文件 '''file.txt''' 不存在时,将产生以下结果: <pre> Value of errno: 2 Error opening file: No such file or directory </pre> [[c standard library errno h|C 标准库 - <errno.h>]]
返回至“
C macro errno
”。
下一节:
C_macro_edom