您的位置:首页 > 运维架构 > Linux

玩玩linux下的errno, perror, strerror

2015-04-30 22:30 411 查看
       少说废话, 多玩程序:

#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]$ 

      用不着多说。

      
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: