errno 两个相关的打印出错信息函数 strerror和perror

一.源代码:

#include "apue.h"

#include


int main(int argc, char *argv[])
{
        fprintf(stderr, "EACCES:%s\n",strerror(EACCES) );
        errno = ENOENT;
        perror(argv[0]);
        exit(0);

}


二.编译:

R*_*G:gcc -Wall -ggdb3 -o 1_6 1_6.c
In file included from apue.h:128,
                 from 1_6.c:1:
error.c: In function `err_doit':
error.c:106: warning: implicit declaration of function `vsnprintf'
error.c:108: warning: implicit declaration of function `snprintf'



三、运行结果:

R*_*G:./1_6
EACCES:Permission denied
./1_6: No such file or directory
R*_*G:


你可能感兴趣的:(apue)