In C, strerror() turns an error number into a short message you can print. You usually pass errno right after a library call fails.
The error number is required. The result is a pointer to text that the library owns, so do not free it or change it. Read errno before another call replaces it. Include <string.h> and <errno.h>.
Syntax
Pass the error number. That is usually errno just after a call fails.
C
strerror(errno);
Call
What it does
strerror(errno)
Looks up a short message for the current errno value.
Include <string.h> and <errno.h>. Exact wording can differ by OS and locale.
Library declarations
C
char *strerror(int errnum);
Parameters
Parameter
Description
errnum
Required. The error number, usually errno right after the call that failed.
Return Value
Return Value
Description
Message pointer
Points to library-owned text. Do not free it or change it.
C Examples
Example 1 — Look Up a Known Code
Pass an errno.h constant directly to see its message.