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