perror


Error processing

[Classification]

Standard library

[Syntax]

#include <stdio.h>

void perror(const char *s);

[Description]

This function outputs to stderr the error message that corresponds to global variable errno.

The message that is output is as follows.

When s is not NULL

fprintf(stderr, "%s:%s\n", s, s_fix);

When s is NULL

fprintf(stderr, "%s\n", s_fix);

 

s_fix is as follows.

When errno is EDOM

"EDOM error"

When errno is ERANGE

"ERANGE error"

When errno is 0

"no error"

Otherwise

"error xxx" (xxx is abs (errno) % 1000)

[Example]

#include    <stdio.h>
#include    <errno.h>
void func(double x) {
        double  d;
        errno = 0;
        d = exp(x);
        if(errno)
                perror("func1");    /*If a calculation exception is generated by exp 
                                      perror is called.*/
}