Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <string.h>
char *strerror(int errnum);
Maps the error number in errnum to an error message string. The errnum must be a valid errno value.
This function does not produce a locale-dependent error message string.
strerror() returns a pointer to the string, which may be overwritten by a subsequent call to strerror().
/* This example opens a file and prints a runtime error message if an
error occurs.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(void)
{
FILE *stream;
⋮
if ((stream = fopen("myfile.dat", "r")) == NULL)
printf(" %s \n", strerror(errno));
}