strerror, _strerror, _wcserror, __wcserror
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

strerror, _strerror, _wcserror, __wcserror

Get a system error message (strerror, _wcserror) or prints a user-supplied error message (_strerror, __wcserror). More secure versions of these functions are available; see strerror_s, _strerror_s, _wcserror_s, __wcserror_s .

char *strerror(
   int errnum 
char *_strerror(
   const char *strErrMsg 
wchar_t * _wcserror(
   int errnum 
wchar_t * __wcserror(
   const wchar_t *strErrMsg 


Error number.


User-supplied message.

All these functions return a pointer to the error-message string. Subsequent calls can overwrite the string.

The strerror function maps errnum to an error-message string, returning a pointer to the string. Neither strerror nor _strerror actually prints the message: For that, you need to call an output function such as fprintf:

if (( _access( "datafile",2 )) == -1 )
   fprintf( stderr, _strerror(NULL) );

If strErrMsg is passed as NULL, _strerror returns a pointer to a string containing the system error message for the last library call that produced an error. The error-message string is terminated by the newline character ('\n'). If strErrMsg is not equal to NULL, then _strerror returns a pointer to a string containing (in order) your string message, a colon, a space, the system error message for the last library call producing an error, and a newline character. Your string message can be, at most, 94 characters long.

The actual error number for _strerror is stored in the variable errno. The system error messages are accessed through the variable _sys_errlist, which is an array of messages ordered by error number. _strerror accesses the appropriate error message by using the errno value as an index to the variable _sys_errlist. The value of the variable _sys_nerr is defined as the maximum number of elements in the _sys_errlist array. To produce accurate results, call _strerror immediately after a library routine returns with an error. Otherwise, subsequent calls to strerror or _strerror can overwrite the errno value.

_wcserrorand __wcserrorare wide-character versions of strerrorand _strerror, respectively.

_strerror, _wcserror, and __wcserrorare not part of the ANSI definition but are instead Microsoft extensions to it. Do not use them where portability is desired; for ANSI compatibility, use strerror instead.

Generic-Text Routine Mappings

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined






Required header





_wcserror, __wcserror


For additional compatibility information, see Compatibility in the Introduction.

See the example for perror.

© 2016 Microsoft