cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstring (string.h) : strerror
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstring (string.h)
functions:
· memchr
· memcmp
· memcpy
· memmove
· memset
· strcat
· strchr
· strcmp
· strcoll
· strcpy
· strcspn
· strerror
· strlen
· strncat
· strncmp
· strncpy
· strpbrk
· strrchr
· strspn
· strstr
· strtok
· strxfrm
macros:
· NULL
types:
· size_t

-

strerror function
char * strerror ( int errnum );
<cstring>

Get pointer to error message string

Interprets the value of errnum generating a string describing the error that usually generates that error number value in calls to functions of the C library.

The returned pointer points to a statically allocated string, which shall not be modified by the program. Further calls to this function will overwrite its content.

The error strings produced by strerror depend on the developing platform and compiler.

Parameters

errnum
Error number.

Return Value

A pointer to the error string describing error errnum.

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;
}

A possible output:

Error opening file unexist.ent: No such file or directory

See also

perror Print error message (function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us