strerror -- 识别错误代码,返回描述的字符串

来源:互联网 发布:gprs网络通信模块收费 编辑:程序博客网 时间:2024/06/15 17:11

strerror

strerror - 函数返回一个指针,这个指针指向一个字符串;这个字符串是被传递的错误代码数(errnum)所表示的错误。
原型:

    #include <string.h>    char *strerror(int errnum);

实例:

#include <stdio.h>#include <pthread.h>#include <errno.h>#include <string.h>int main(void ){    pthread_t thread;   /* apply a variable but uninitialized */    int status = 0;    /* test what error number will return */    status = pthread_join(thread, NULL);    if (status != 0) {        fprintf(stderr, "error %d: %s\n", status, strerror (status));    }    return status;}

结果:

root@ubuntu:/mnt/hgfs/PFolder/Programming with POSIX Threads/Chapter1.9/bin# ./main.out error 3: No such processroot@ubuntu:/mnt/hgfs/PFolder/Programming with POSIX Threads/Chapter1.9/bin# 
阅读全文
0 0
原创粉丝点击