Borland C++ reference

perror

raw OCR

Prints a system error message.

Defined in header <stdio.h>

Syntax

#include <stdio.h>
void perror(const char *s);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

perror prints to the stderr stream (normally the console) the system error message for the last library routine that produced the error.

First the argument s is printed, then a colon, then the message corre-sponding to the current value of the global variable errno, and finally a newline. The convention is to pass the file name of the program as the argument string.

The array of error message strings is accessed through the global variable sys_errlist. The global variable errno can be used as an index into the array to find the string corresponding to the error number. None of the strings includes a newline character.

The global variable sys_nerr contains the number of entries in the array.

Refer to errno, sys_errlist, and sysjnerr in Chapter 3, "Global variables," for more information.

Return value

None.

See also

Example

#include <stdio.h>
int main (void)
{
   FILE *fp;
   fp = fopen ("perror.dat", "r");
   if (!fp)
      perror ("Unable to open file for reading");
return

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.