6.20.14 strerror Function

Gets an internal error message.

Include

<string.h>

Prototype

char *strerror(int errcode);

Argument

errcode
number of the error code

Return Value

Returns a pointer to an internal error message string corresponding to the specified error code errcode.

Remarks

The strings for the following error conditions are returned by this function.
Error conditionString
EILSEQ"Illegal byte sequence"
EDOM"Domain error"
ERANGE"Result not representable"
EOVERFLOW"Value too large for data type"
EINVAL"Invalid argument"
0"No error information"

The array pointed to by strerror may be overwritten by a subsequent call to this function, so it is not thread safe.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <string.h>
#include <math.h>
#include <stdio.h>
#include <errno.h>

int main()
{
    double result, x=-9.0;

    result = log(x);
    if(errno)
	    printf("Log generated %s\n", strerror(errno));
    else
	    printf("Log of %g is %g\n", x, result);
}

Example Output

Log generated Mathematics argument out of domain of function