#include <string.h> char *strerror(int errnum);
strerror
maps the error number in errnum
to an error message
string.
The message returned by strerror
provides much less information than
the library-generated message for an error. For instance, the result of
strerror(ERANGE)
is "math function value out of bounds," while the
library message for this error includes the name and arguments of the failing
function.
#include <stdio.h> #include <string.h> #include <errno.h> #include <lclib.h> main() { FILE *f; char *filename; quiet(1); /* Suppress library messages. */ f = fopen(filename, "w"); /* Provide error message if open fails. */ if (!f) printf ("Open failed. %sn", strerror(errno)); }
perror
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.