This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.
Released under the GNU General Public License.
strerror
Prototype
#include <string.h>
char *strerror(int errnum);
Description
Returns a string describing the error code errnum
. The returned
string cannot be modified.
Example
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* fcheck.c: check if the argument file exists.
* usage: fcheck <filename>
*/
int main(int argc, char **argv)
{
FILE *f;
if (argc != 2) {
fprintf(stderr, "usage: %s <filename>\n", argv[0]);
return EXIT_FAILURE;
}
if ((f = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "%s:%s: %s\n", argv[0], argv[1],
strerror(errno));
return EXIT_FAILURE;
}
printf("The `%s' file is readable.\n", argv[1]);
fclose(f);
return EXIT_SUCCESS;
}
References
ISO C 9899:1990 7.11.6.2