strerror()用法理解
来源:互联网 发布:局域网ip欺骗软件 编辑:程序博客网 时间:2024/06/06 08:59
12345678910111213
/* strerror example : error list */#include <stdio.h>#include <string.h>#include <errno.h>int main (){ FILE * pFile; pFile = fopen ("unexist.ent","r"); if (pFile == NULL) printf ("Error opening file unexist.ent: %s\n",strerror(errno)); return 0;}
strerror()方法与perror()的用法十分相似。先谈谈perror()的用法,这个方法用于将上一条语句(方法)执行后的错误打印到标准输出上。一般情况下(没有使用重定向的话),就是输出到控制台上。
但是,如果我需要了解另外一个进程的某一个方法执行的错误,或者更briefly,我就希望将错误打印到一个文件里面,perror()就不太合适了!
为了实现我刚刚说到的要求,我们首先要将错误放到一个字符串里面。这个时候,strerror()就合适了!
strerror(errno)
首先,系统会根据上一条语句的执行错误情况,将errno赋值.。关于这点,我们首先明白两点。第一,errno是一个系统变量,是不需要我们赋值或者声明的。第二,errno是一个int类型的变量,而且其中的值对应一种特定错误类型然后,关于streorror()本身,可以这么理解。顾名思义,streorror=string+error,就是将errno值翻译成描述错误类型的string语句!
- strerror()用法理解
- strerror()的用法理解
- strerror
- strerror
- strerror
- strerror
- strerror()
- 区别stderr,strerror,errno的用法
- 错误输出函数perror和strerror用法
- fprintf、stderr、strerror(errno)、strncpy和strcpy的用法
- strerror()函数
- strerror() 函数
- strerror函数
- strerror(errno)
- strerror函数
- strerror, strerror_r
- strerror函数
- c strerror
- Android程序的基本构件
- 展望未来,总结过去10年的程序员生涯(转载自某IT资深前辈)
- 学习OpenCV——粒子滤波(网上两篇文章总结)
- html5(熊与蘑菇)一步一步学做游戏 第一回:游戏分析
- 一些常用的软件滤波方法
- strerror()用法理解
- asp.net的重要的东西
- html5(熊与蘑菇)一步一步学做游戏 第二回:让蘑菇随鼠标动起来
- 关于EC2的AKI和ARI
- 解析Java对象的equals()和hashCode()的使用
- Android StrictMode 介绍
- html5(熊与蘑菇)一步一步学做游戏 第三回:让熊动起来
- Java线程:线程的同步与锁
- 关于cvContourArea