perror
void  perror ( const char * string );
stdio.h
  cplusplus.com  

Print error message.
  Transcribes the the value of the global variable errno into a string and prints that string to stderr (standard error output, generally the screen).
  errno describes the last error produced by a call to a library routine. It is an index for the global variable sys_errlist that contains an array of strings describing library routine errors. These error strings do not include the ending newline character (\n). The number of entries is defined by the global variable sys_nerr.
  If the parameter string is not NULL, string is printed followed by a colon (:) and the error description.
  After the error description a newline character (\n) is appended.
  The standard convention is to pass the program name as the string parameter.
  perror should be called right after a library routine returns an error or it can be overwritten by further calls.

Parameters.

string
Message to be printed before the error message.

Return Value.
  none

Portability.
  Defined in ANSI-C.

Example.

/* perror example */
#include <stdio.h>

main ()
{
  FILE * pFile;
  pFile=fopen ("unexist.ent","rb");
  if (pFile==NULL)
    perror ("This error has occurred");
  else
    fclose (pFile);
  return 0;
}
  If the file unexist.ent doesn't exist something similar to this Output is expected:
This error has occurred: No such file or directory

See also.
  clearerr, strerror, ferror, feof


© The C++ Resources Network, 2000