strerror, _strerror, _wcserror, __wcserror
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

strerror, _strerror, _wcserror, __wcserror

Get a system error message (strerror, _wcserror) or prints a user-supplied error message (_strerror, __wcserror).

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.

Return Value

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.

_wcserror and __wcserror are wide-character versions of strerror and _strerror, respectively.

_strerror, _wcserror, and __wcserror are 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
_tcserror strerror strerror _wcserror


Routine Required header Compatibility
strerror <string.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_strerror <string.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_wcserror <string.h> Win 98, Win Me, Win NT, Win 2000, Win XP
__wcserror <string.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


See the example for perror.

See Also

String Manipulation Routines | clearerr | ferror | perror | Run-Time Routines and .NET Framework Equivalents

© 2016 Microsoft