[Previous]
[Contents]
[Next]

perror()

print, in stderr, the message associated with the value of errno

Synopsis:

#include <stdio.h>

void perror( const char *prefix );

Description:

The perror() function prints, on the file designated by stderr, the error message corresponding to the error number contained in errno. The perror() function writes first the string pointed to by prefix to stderr. This is followed by a colon (:), a space, the string returned by strerror(errno), and a newline character.


Note: Because perror() uses the fprintf() function, errno can be set when an error is detected during the execution of that function.

Examples:

#include <stdio.h>

void main()
  {
    FILE *fp;

    fp = fopen( "data.fil", "r" );
    if( fp == NULL ) {
    perror( "Unable to open file" );
    }
  }

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

clearerr(), errno, feof(), ferror(), strerror()

"Messages generated by perror()" in Appendix A: Implementation-Defined Behavior


[Previous]
[Contents]
[Next]