本文主要是介绍玩玩linux下的errno, perror, strerror,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
少说废话, 多玩程序:
#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]$
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下的errno, perror, strerror的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!