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.

See the section “Messages Generated by the perror() Function” in Appendix A: Implementation-defined Behavior for more information.

Returns:

Nothing

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

See also:

errno, strerror()

Examples:

#include <stdio.h>

void main()
  {
    FILE *fp;

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

Classification:

ANSI

Systems:

All (except DOS/PM)