VMS Help  —  CRTL  perror
    Writes a short error message to stderr describing the current
    value of errno.

    Format

      #include  <stdio.h>

      void perror  (const char *str);

1  –  Argument

 str

    Usually the name of the program that caused the error.

2  –  Description

    The perror function uses the error number in the external
    variable errno to retrieve the appropriate locale-dependent
    error message. The function writes out the message as follows:
    str (a user-supplied prefix to the error message), followed by a
    colon and a space, followed by the message itself, followed by a
    new-line character.

    See also strerror.

3  –  Example

        #include <stdio.h>
        #include <stdlib.h>

        main(argc, argv)
            int argc;
            char *argv[];
        {
            FILE *fp;

            fp = fopen(argv[1], "r");   /* Open an input file. */
            if (fp == NULL) {

                /* If the fopen call failed, perror prints out a        */
                /* diagnostic:                                          */
                /*                                                      */
                /*  "open: <error message>"                             */
                /*  This error message provides a diagnostic explaining */
                /*  the cause of the failure.                           */

                perror("open");
                exit(EXIT_FAILURE);
            }
            else
                fclose(fd) ;
        }
Close Help