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

strerror

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

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

实例:

#include 
#include 
#include 
#include 

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 process
root@ubuntu:/mnt/hgfs/PFolder/Programming with POSIX Threads/Chapter1.9/bin# 

你可能感兴趣的:(知识小记)