cplusplus.com > reference > cstring > strerror
strerror
<string.h>
  cplusplus.com  
char *  strerror ( int errnum );

Get pointer to error message string.
  Returns a pointer to a string with the error message corresponding to the errnum error number.
  The returned pointer points to a statically allocated string. Further calls to this function will overwrite its content.
  This funcion can be called with global variable errno declared in <errno.h> to get the last error produced by a call to a C library function.

Parameters.

errnum
Error number.

Return Value.
  A pointer to the error string describing error errnum.

Portability.
  Defined in ANSI-C.

Example.

/* strerror example : error list */
#include <stdio.h>
#include <string.h>
#include <errno.h>

int main ()
{
  FILE * pFile;
  pFile = fopen ("unexist.ent","r");
  if (pFile == NULL)
    printf ("Error opening file unexist.ent: %s\n",strerror(errno));
  return 0;
}
Output:
Error opening file unexist.ent: No such file or directory

See also.
  cstdio/clearerr, cstdio/perror


© The C++ Resources Network, 2000