Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>strerror() save system error message</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 strerror()              Save System Error Message

 #include   <string.h>                   Required for declarations only

 char       *strerror( errnum );
 int        errnum;                      Error number

    strerror() maps errnum to an error message string, returning a
    pointer to the string. To print the the message use an output
    function such as printf().

    Returns:    strerror() returns a pointer to the error message
                associated with errnum.

      Notes:    In MSC 5.0 and later, strerror() is a new function that
                conforms to the ANSI standard; _strerror() in MSC 5.0 and
                later is identical to strerror() in MSC 4.0, and is a
                Microsoft extension not supported by the ANSI standard
                library.

                Call strerror() immediately after a routine returns,
                before errnum is overwritten by subsequent routine calls.

                strerror() is unlike perror() in that it does not
                actually print any messages.  The program is responsible
                for printing the returned message, as shown in the
                example below.

 Portability:   ANSI standard.

   -------------------------------- Example ---------------------------------

    This example tries to open a file, and prints a customized error
    message and exits if unable to do so.

           #include <string.h>
           #include <stdio.h>             /* for printf*/
           #include <fcntl.h>             /* constants defined */
           #include <sys\types.h>
           #include <sys\stat.h>          /* constants defined */
           #include <io.h>                /* for open */

           extern int errno;
           int errnum;
           int fh;

           main()
           {
                 if ((fh = open("invoice.dat",O_RDWR)) == -1)
                    {
                    errnum = errno;
                    printf(strerror( errnum ));
                    exit(1);
                    }

                 . . . read and use "invoice.dat" . . .
            }


See Also: _strerror() perror()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson