玩玩linux下的errno, perror, strerror
2015-04-30 22:30
411 查看
少说废话, 多玩程序:
[taoge@localhost learn_c]$ ./a.out
0
0: Success
xxxSuccess
------------------------------------
1: Operation not permitted
xxxOperation not permitted
------------------------------------
2: No such file or directory
xxxNo such file or directory
------------------------------------
3: No such process
xxxNo such process
------------------------------------
4: Interrupted system call
xxxInterrupted system call
------------------------------------
[taoge@localhost learn_c]$
用不着多说。
#include <stdio.h> #include <errno.h> int main() { printf("%d\n", errno); int i = 0; for(i = 0; i < 5; i++) { errno = i; char szTest[100] = {0}; snprintf(szTest, sizeof(szTest), "%d", errno); perror(szTest); printf("xxx%s\n", strerror(errno)); printf("------------------------------------\n"); } return 0; }结果:
[taoge@localhost learn_c]$ ./a.out
0
0: Success
xxxSuccess
------------------------------------
1: Operation not permitted
xxxOperation not permitted
------------------------------------
2: No such file or directory
xxxNo such file or directory
------------------------------------
3: No such process
xxxNo such process
------------------------------------
4: Interrupted system call
xxxInterrupted system call
------------------------------------
[taoge@localhost learn_c]$
用不着多说。
相关文章推荐
- Linux系统编程之错误处理:perror,strerror和errno
- 关于Linux系统编程的错误处理:errno、perror、strerror
- linux下错误的捕获:errno、perror和strerror的使用
- linux系统编程之错误处理:perror,strerror和errno
- linux下错误的捕获:errno、strerror和perror的使用
- linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- Linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- 关于C语言自带的错误机制,可选的提示错误函数perror(),strerror(errno),个人测试结果
- linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- 转: linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno和strerror的使用
- linux下错误的捕获:errno(errno.h)和strerror(string.h)的使用
- linux下错误的捕获:errno和strerror的使用