Chapter Contents

Previous

Next
perror

perror



Write Diagnostic Message

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <stdio.h>

void perror(const char *prefix);


DESCRIPTION

perror writes a diagnostic message to the standard error file, stderr . The message is preceded by the prefix string, a colon, and a blank. It is followed by a new-line character.

The text of the message is based on the value of the external integer errno , which is set by the library when an error or warning condition is detected.

Note:    If the library writes a diagnostic for an error condition, this message is usually more precise than the message that would be written by perror . This is because, in many cases, one value for errno corresponds to a number of different conditions, and other information about the error (for example, the name of a file) is unavailable to perror .  [cautionend]

The texts of the messages and the precise meanings of the possible errno values are implementation dependent. The texts and explanations of the SAS/C library messages are provided in the SAS/C Software Diagnostic Messages.


RETURN VALUE

perror has no return value.


EXAMPLE

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

main()
{
   FILE *f;
   quiet(1);           /* Suppress library messages. */
   f = fopen("myfile","r");

   if (!f)
      if (errno == ENFOUND) fprintf(stderr,
          "Error in input phase: myfile not found.\n");
      else perror("error in input phase");

   quiet(0);                /* Allow messages again. */
}


RELATED FUNCTIONS

quiet , strerror


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.