strerror ()- 设置指向运行时错误消息的指针

格式

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

语言级别

ANSI

线程安全

描述

strerror() 函数将 errnum 中的错误号映射到错误消息字符串。

返回值

strerror() 函数返回指向字符串的指针。 它不会返回 NULL 值。 errno 的值可以设置为 ECONVERT (转换错误)。

示例

此示例打开文件并在发生错误时打印运行时错误消息。
#include <stdlib.h>
#include <string.h>
#include <errno.h>
 
int main(void)
{
   FILE *stream;
 
   if ((stream = fopen("mylib/myfile", "r")) == NULL)
      printf(" %s \n", strerror(errno));
 
}
 
/*  This is a program fragment and not a complete function example  */

相关信息