少说废话, 多玩程序:
#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]$
用不着多说。